1

I want to display a text and next to the text a dynamic number of images that should be floated to the right side.

That is what I have:

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

My problem is that if icon1 is not visible (I control on my Java code) icon2 is not displayed on the right side anymore. It overlayed text1, because the referenced icon1 is missing.

4

1 回答 1

2

好吧,要么你上面的布局不完整(如果是这样,你应该发布完整的东西)或者你的 id 被破坏了(你已经icon2@+id/1它应该在@+id/icon1.

尝试设置android:layout_alignWithParentIfMissing="true"icon2更正布局 ID。

于 2011-05-13T17:53:52.920 回答