Nik*_*nko 3 android android-layout android-constraintlayout constraint-layout-chains
我有一个带有ImageView的ConstraintLayout和带链样式的3个链式TextView:spread_inside
<android.support.design.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/space_normal"
android:paddingEnd="@dimen/space_normal"
android:paddingStart="@dimen/space_normal"
android:paddingTop="@dimen/space_big">
<ImageView
android:id="@+id/ivImage"
android:layout_width="@dimen/feed_list_image_size"
android:layout_height="@dimen/feed_list_image_size"
android:layout_marginBottom="@dimen/space_normal"
android:contentDescription="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:src="@color/debug_3" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/space_normal"
android:ellipsize="end"
android:maxLines="3"
android:textSize="@dimen/text_size_big"
app:layout_constraintBottom_toTopOf="@+id/tvContent"
app:layout_constraintEnd_toStartOf="@+id/ivImage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside"
app:textAllCaps="true"
tools:text="@tools:sample/lorem" />
<TextView
android:id="@+id/tvContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/space_big"
android:layout_marginTop="@dimen/space_normal"
android:ellipsize="end"
android:maxLines="4"
android:textColor="@color/gray_600"
android:textSize="@dimen/text_size_normal"
app:layout_constraintBottom_toTopOf="@+id/tvDate"
app:layout_constraintEnd_toEndOf="@+id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvTitle"
tools:text="@tools:sample/lorem/random" />
<TextView
android:id="@+id/tvDate"
style="@style/AppTheme.ItemFeedList.Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/space_normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvContent"
tools:text="@tools:sample/date/hhmm" />
</android.support.constraint.ConstraintLayout>
</android.support.design.card.MaterialCardView>
Run Code Online (Sandbox Code Playgroud)
这在编辑器中呈现了一个漂亮而灵活的布局:
但有时顶视图被"推"出其约束,因此文本渲染是错误的(剪裁).这很奇怪,因为spread_inside链条样式应该膨胀并缩小中间视图.从布局检查器:
它有什么问题?
版本1.1中的更改ConstraintLayout可能对您有所帮助.尝试设置app:layout_constrainedHeight=”true”你的麻烦TextView.来自ConstraintLayout的开发人员指南:
WRAP_CONTENT:强制约束(在1.1中添加)
如果维度设置为WRAP_CONTENT,则在1.1之前的版本中,它们将被视为文字维度 - 这意味着约束不会限制生成的维度.虽然通常这足够(并且更快),但在某些情况下,您可能希望使用WRAP_CONTENT,但仍然强制执行约束以限制结果维度.在这种情况下,您可以添加一个相应的属性:
app:layout_constrainedWidth ="true | false"
app:layout_constrainedHeight ="true | false"
| 归档时间: |
|
| 查看次数: |
1647 次 |
| 最近记录: |