TextView匹配所有宽度

时间:2017-03-11 15:52:10

标签: android

我将TextView设置为ImageView,但为什么要覆盖所有宽度?如果我设置android:layout_alignParentRight并且仍匹配父项

,则没有区别

enter image description here

<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>

3 个答案:

答案 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"/>
相关问题