我有以下布局:
<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:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
它是这样显示的:
应该是:
我需要什么来解决这个问题?我尝试过使用准则和水平偏差,还尝试使用 RelativeLayout 而不是 ConstraintLayout 对其进行约束,但到目前为止没有任何帮助。
最佳答案
您可以尝试将 itemValue
宽度设置为 0 并改用 layout_constraintStart_toEndOf
:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
如果您打算将文本对齐到末尾,您可能需要使用 android:gravity="right|end"
。
关于android - 避免在 ConstraintLayout 中重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53422468/