ConstraintLayout内的TextView剪辑文本和layout_margin无法正确显示

zon*_*nda 5 android android-constraintlayout

我用:compile'c​​om.android.support.constraint:constraint-layout:1.0.2'

主要问题是:

  1. layout_margin无法正确显示;
  2. 子文本视图的文本被剪裁.

详情如下:

这是我的xml:

<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="wrap_content"
    android:background="@android:color/darker_gray"
    android:padding="8dp">

    <ImageView
        android:id="@+id/reviewer_avatar"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:background="@color/colorAccent"
        android:contentDescription="@string/avatar"
        android:layout_margin="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/reviewer_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/reviewer_name"
        android:textSize="16sp"
        app:layout_constraintBottom_toTopOf="@+id/comment_floor"
        app:layout_constraintLeft_toRightOf="@+id/reviewer_avatar"
        app:layout_constraintTop_toTopOf="@+id/reviewer_avatar"
        app:layout_constraintVertical_chainStyle="packed"/>

    <TextView
        android:id="@+id/comment_floor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/reviewer_floor_text"
        android:textSize="12sp"
        app:layout_constraintBottom_toBottomOf="@+id/reviewer_avatar"
        app:layout_constraintLeft_toRightOf="@+id/reviewer_avatar"
        app:layout_constraintTop_toBottomOf="@+id/reviewer_name"/>

    <TextView
        android:id="@+id/comment_period"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dp"
        android:text="@string/comment_period_text"
        android:textSize="12sp"
        app:layout_constraintLeft_toRightOf="@+id/comment_floor"
        app:layout_constraintTop_toBottomOf="@+id/reviewer_name"/>

    <TextView
        android:id="@+id/comment_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/large_text"
        android:textSize="16sp"
        app:layout_constraintLeft_toRightOf="@+id/reviewer_avatar"
        app:layout_constraintTop_toBottomOf="@+id/reviewer_avatar"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的截图:

这是我的截图

Pav*_*van 9

这主要是两个问题

  1. 您缺少为父视图设置正确的 约束
  2. ConstraintLayout中有一个错误,其中wrap_content已解决,现在您必须使用match_constraint(0dp)layout_constraintWidth_default属性来解决此问题,将以下两个属性添加到largetext视图
android:layout_width="0dp"
app:layout_constraintWidth_default="wrap"
app:layout_constraintRight_toRightOf="parent"
Run Code Online (Sandbox Code Playgroud)

所以你的大文本视图就像

<TextView
        android:id="@+id/comment_content"
        android:layout_width="0dp"
        app:layout_constraintWidth_default="wrap"
        android:layout_height="wrap_content"
        android:text="@string/large_text"
        android:textSize="16sp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/reviewer_avatar"
        app:layout_constraintTop_toBottomOf="@+id/reviewer_avatar"/>
Run Code Online (Sandbox Code Playgroud)


zon*_*nda 4

我想我找到了子文本视图的文本被剪裁的答案。

\n\n

我改成\xef\xbc\x9a

\n\n
<TextView\n    android:id="@+id/comment_content"\n    android:layout_width="wrap_content"\n    android:layout_height="wrap_content"\n    android:text="@string/large_text"\n    android:textSize="16sp"\n    app:layout_constraintLeft_toRightOf="@+id/reviewer_avatar"\n    app:layout_constraintTop_toBottomOf="@+id/reviewer_avatar"/>\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
<TextView\n        android:id="@+id/comment_content"\n        android:layout_width="0dp"\n        android:layout_height="wrap_content"\n        android:text="@string/large_text"\n        android:textSize="16sp"\n        app:layout_constraintLeft_toRightOf="@+id/reviewer_avatar"\n        app:layout_constraintTop_toBottomOf="@+id/reviewer_avatar"\n        app:layout_constraintRight_toRightOf="parent"/>\n
Run Code Online (Sandbox Code Playgroud)\n\n

这样就可以解决问题了!

\n\n

但这样一来,TextView就无法伸缩\xef\xbc\x8,只能填充宽度。

\n\n

最后,更好的答案:

\n\n
  <TextView\n        android:id="@+id/comment_content"\n        android:layout_width="0dp"\n        android:layout_height="wrap_content"\n        android:text="@string/reviewer_name"\n        android:textSize="16sp"\n        app:layout_constraintHorizontal_bias="0"\n        app:layout_constraintLeft_toLeftOf="@+id/reviewer_name"\n        app:layout_constraintRight_toRightOf="parent"\n        app:layout_constraintTop_toBottomOf="@+id/reviewer_avatar"\n        app:layout_constraintWidth_default="wrap"/>\n
Run Code Online (Sandbox Code Playgroud)\n