我将TextView
设置为ImageView
,但为什么要覆盖所有宽度?如果我设置android:layout_alignParentRight
并且仍匹配父项
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/removeButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="25dp"
app:srcCompat="@drawable/remove_playlist"
android:layout_height="25dp" />
<TextView
android:id="@+id/title"
tools:text="tttttttttttt ttttttt tttttttt tttttttttttt tttttt ttttttt tttttttt ttttttttt"
android:textColor="@android:color/black"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignRight="@id/removeButton"
android:layout_alignEnd="@id/removeButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
答案 0 :(得分:1)
您应该使用属性toLeftOf
而不是alignRight
<TextView
android:id="@+id/title"
tools:text="tttttttttttt ttttttt tttttttt tttttttttttt tttttt ttttttt tttttttt ttttttttt"
android:textColor="@android:color/black"
android:ellipsize="end"
android:maxLines="1"
android:layout_toLeftOf="@id/removeButton"
android:layout_toEndOf="@id/removeButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
alignRight
将两个观点彼此对齐
答案 1 :(得分:0)
我猜你必须删除
1 * 3 4
5 2 * *
9 * * *
13 * * _
1 2 3 *
5 * * 4
9 * * *
13 * * _
在ImageView中并替换
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
通过
android:layout_alignRight="@id/removeButton"
android:layout_alignEnd="@id/removeButton"
在你的TextView
中答案 2 :(得分:0)
只是对@Farid做了一点调整回答属性是leftOf和toStartOf。 toEndOf属性可以与toRightOf属性一起使用:
<TextView
android:id="@+id/title"
tools:text="tttttttttttt ttttttt tttttttt tttttttttttt tttttt ttttttt tttttttt ttttttttt"
android:textColor="@android:color/black"
android:ellipsize="end"
android:maxLines="1"
android:layout_toLeftOf="@id/removeButton"
android:layout_toStartOf="@id/removeButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>