Android 图像视图旁边的文本视图

Android 图像视图旁边的文本视图,android,android-layout,Android,Android Layout,我正在尝试将文本视图和图像视图直接置于其右侧。现在,图像部分重叠在文本的最右侧,因此如果输入的文本很长,则图像“覆盖”文本。我在文本上有一个椭圆设置,但我需要文本视图在ImageView的左边框处“停止” 文本视图布局设置: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentL

我正在尝试将文本视图和图像视图直接置于其右侧。现在,图像部分重叠在文本的最右侧,因此如果输入的文本很长,则图像“覆盖”文本。我在文本上有一个椭圆设置,但我需要文本视图在ImageView的左边框处“停止”

文本视图布局设置:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
ImageView布局设置:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
试试这个:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/iv"
        android:singleLine="true"
        android:maxLines="1"
        android:ellipsize="end"
        .... />

    <!-- background == @null if you don't want default button background -->
    <ImageButton
        android:id="@id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_margin="3dp"
        android:background="@null"  
        .... />

</RelativeLayout>

编辑

请参阅有关此功能为何有效以及所发布问题为何无效的评论。也来看看


有关
end/right
start/left
属性的参考信息

查看drawableX属性,例如TextView@zgc7009我确实看到了,但我需要图像是可点击的,这就是为什么我把它作为自己的图像视图(它是一个删除X图标)
toLeftOf
是我一直缺少的东西!我在ImageButton上尝试了
toRightof
,但没有成功,所以我没有尝试其他方法。为什么TextView上的
toLeftOf
可以工作,而ImageView上的
toRightOf
不能工作?因为如果TextView占据整个屏幕宽度,则toRightOf会将ImageView推到屏幕右侧。使用父对齐执行toLeftOf可以使ImageView绘制在父对齐的右侧,而TextView绘制在父对齐的左侧。我过去很讨厌搞清楚XML视图,一旦你对它有了更多的了解,你能做什么真是太神奇了。有太多的对齐选项,坦白说,我不明白它们是如何协同工作的。我想熟能生巧。谢谢