ConstraintLayout在textview中切断文本

时间:2017-05-02 12:57:54

标签: android xml android-constraintlayout

我有一个ConstraintLayout,其中包含几个观点,由于某种原因,我的textview会在句子末尾被截断。 textview约束在左侧和顶部。它是tv_product_description textview

<android.support.constraint.ConstraintLayout
    android:id="@+id/ll_product_holder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:background="@drawable/drawable_border"
    android:orientation="vertical">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/iv_product_image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="9dp"
        android:layout_marginStart="9dp"
        android:layout_marginTop="13dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/price_holder"
        fresco:actualImageScaleType="centerCrop"
        fresco:placeholderImage="@drawable/placeholder2"/>

    <TextView
        android:id="@+id/tv_product_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="9dp"
        android:layout_marginStart="9dp"
        android:layout_marginTop="13dp"
        android:text="@{historyItem.productId}"
        app:layout_constraintLeft_toRightOf="@+id/iv_product_image"
        app:layout_constraintTop_toBottomOf="@+id/price_holder"/>

    <TextView
        android:id="@+id/tv_product_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="9dp"
        android:layout_marginStart="9dp"
        android:ellipsize="end"
        android:maxLines="2"
        android:text="@{historyItem.productDescription}"
        app:layout_constraintLeft_toRightOf="@+id/iv_product_image"
        app:layout_constraintTop_toBottomOf="@+id/tv_product_id"/>

</android.support.constraint.ConstraintLayout>

Here you can see the textview being cut off.

3 个答案:

答案 0 :(得分:17)

请添加正确的约束

app:layout_constraintRight_toRightOf="parent"

请设置宽度0dp,如

android:layout_width="0dp"

<强>输出

enter image description here

答案 1 :(得分:0)

有关此主题的最佳和最新答案可以在这里找到:

View is pushed out of its constraints in ConstraintLayout

Wrap_content view inside a ConstraintLayout stretches outside the screen

它们描述了如何使用ConstraintLayout 1.1引入的app:layout_constrainedWidth-Property。

答案 2 :(得分:0)

对我来说,这样做具有以下目的

app:layout_constraintEnd_toEndOf="parent"

,宽度为

android:layout_width="0dp"