【问题标题】:ConstraintLayout cuts off text in textviewConstraintLayout 截断 textview 中的文本
【发布时间】:2017-05-02 12:57:54
【问题描述】:

我有一个ConstraintLayout,其中有几个视图,出于某种原因,我的textview 在句尾被截断。 textview 被限制在左侧和顶部。是tv_product_descriptiontextview

<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>

【问题讨论】:

    标签: android xml android-constraintlayout


    【解决方案1】:

    请添加正确的约束以及喜欢

    app:layout_constraintRight_toRightOf="parent"
    

    请像这样设置宽度 0dp

    android:layout_width="0dp"
    

    输出

    【讨论】:

    • 我试过添加一个constraintRight,但是textview 搞砸了,好像左边的约束被忽略了,它仍然被切断了。
    • 我已经在我的机器上进行了测试,但问题是你已经给出了一些不属于其父布局的约束。
    • 请尝试添加android:layout_width="0dp"希望它对你有用。
    • 上面的例子没有任何问题..非常感谢
    【解决方案2】:

    对我来说,这可以通过以下方式实现

    app:layout_constraintEnd_toEndOf="parent"
    

    宽度为

    android:layout_width="0dp"
    

    【讨论】:

      【解决方案3】:

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

      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。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-01
        • 2017-01-10
        • 2012-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多