我要显示一个文本,然后在该文本旁边显示应该浮动到右侧的动态数量的图像。
那就是我所拥有的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:padding="7dp"
android:textSize="18sp"
android:textColor="#000"/>
<ImageView
android:id="@+id/icon1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="right"
android:layout_alignParentRight="true"
android:layout_marginTop="10dip"
android:layout_marginRight="6dip"
android:src="@drawable/bus" />
<ImageView
android:id="@+id/icon2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toLeftOf="@+id/1"
android:layout_marginTop="10dip"
android:layout_marginRight="6dip"
android:src="@drawable/tram" />
</RelativeLayout>
我的问题是,如果
icon1
不可见(我控制Java代码),icon2不再显示在右侧。它覆盖了text1
,因为缺少了引用的icon1
。 最佳答案
好吧,要么上面的布局不完整(如果这样,您应该发布完整内容),要么您的ID损坏(将icon2
布置在@+id/1
的左侧,而将其布置在@+id/icon1
的左侧) >。
尝试在android:layout_alignWithParentIfMissing="true"
上设置icon2
并更正布局ID。