android - ConstraintLayout 截断textview中的文字

标签 android xml android-constraintlayout

我有一个 ConstraintLayout,里面有几个 View ,出于某种原因,我的 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.

最佳答案

请同时添加右约束

app:layout_constraintRight_toRightOf="parent"

并且请像这样设置宽度0dp

android:layout_width="0dp"

输出

enter image description here

关于android - ConstraintLayout 截断textview中的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43738525/

相关文章:

Android:Realm.getInstance(context) 返回一个已经关闭的 Realm 实例

android - 使用 Android 应用程序发送射频 (RF) 信号

java - 如何为图像按钮显示 fragment 类型的消息?

Android ConstraintLayout 中心与多个按钮水平对齐

android - ActionBar SearchView 在横向模式下未完全展开

android - 如何在 Xamarin 中为谷歌地图实现标记聚类

java - XML 到 JSON - 转换列表时出现意外行为?

xml - 防止 XSL 1.0 中的 2^n - 1 条件

android - 是否可以在没有动画的情况下在 MotionLayout 中设置结束状态?

android - 为 fragment 设置约束