首页 > 解决方案 > ConstraintLayout中的右文本视图,文本被切断

问题描述

我在 android 中使用 ConstraintLayout 布局。我希望我的图像在左侧,我的文本在图像的右侧。

<?xml version="1.0" encoding="utf-8"?
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/galleryImg"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:onClick="toggleMode"
        android:layout_marginLeft="10dp"
        android:scaleType="centerCrop"
        android:src="@drawable/slider"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        />

    <TextView
        android:id="@+id/galTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="Quick Brown Fox Jumps Over Quick Brown Fox Jumps Over"
        android:textSize="18sp"
        android:layout_alignParentRight="true"
        app:layout_constraintStart_toEndOf="@+id/galleryImg"
        app:layout_constraintTop_toTopOf="@+id/galleryImg" />

</android.support.constraint.ConstraintLayout>

但是我的文本在右侧被切断 - 就像我的文本在第一行结束时.. 它只显示ov并且下一行以Quick开头。

标签: androidtextviewandroid-constraintlayout

解决方案


在这里,这应该工作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/galleryImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:contentDescription="TODO"
        android:src="@drawable/slider"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/galTitle"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:text="Quick Brown Fox Jumps Over Quick Brown Fox Jumps Over"
        app:layout_constraintBottom_toBottomOf="@+id/galleryImg"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/galleryImg"
        app:layout_constraintTop_toTopOf="@+id/galleryImg"/>
</android.support.constraint.ConstraintLayout>

推荐阅读