我有以下布局:覆盖在ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE"
>
<ImageView
android:layout_width="4dp"
android:layout_height="match_parent"
android:background="@color/colorAccent"
/>
<TextView
android:text="12345678911131517192123252729313335373941434547495153555759616365676971737577798183858789"
android:id="@+id/title"
android:textSize="15sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
/>
<TextView
android:text=" text text"
android:id="@+id/prev"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="WHY WHY WHY"
app:layout_constraintTop_toBottomOf="@+id/prev"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
/>
</android.support.constraint.ConstraintLayout>
我们有以下结果: image with this issue
此外,如果我们改变了第一的TextView到文本:“1234567891113151719212325272931333537394143454749515355575961636567697173757779818385878991” (也就是添加2个数字),最后一个TextView会停止关闭前一个。另外,如果我们在上一个TextView中将layout_marginBottom属性更改为0dp(并且文本将像在示例中一样离开),问题也会消失。这个问题的原因是什么?如何解决它?
UPDATE:
在左侧加入具有高度match_parent的路径。因为这个不能在ConstraintLayout中使用paddingBottom。该布局用于RecyclerView,这就是为什么底部元素需要layout_marginBottom。
由于底部边距消失,它并未完全解决问题。 –
如果它是您在xml中需要的最后一个小部件,那么您的'layout_marginBottom'将不起作用 –
不,这只是一个示例,实际上这样的布局具有背景,并且在RecyclerView中使用。 –