1

テキストを表示し、テキストの横に、右側にフロートする必要のある動的な数の画像を表示したいと思います。

それは私が持っているものです:

<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が欠落しているため、オーバーレイされました。

4

1 に答える 1

2

さて、上記のレイアウトが不完全であるか(そうであれば、完全なものを投稿する必要があります)、IDが壊れています(左側に配置する必要があるときにicon2左側にレイアウトしました) 。@+id/1@+id/icon1

android:layout_alignWithParentIfMissing="true"オンに設定しicon2て、レイアウトIDを修正してみてください。

于 2011-05-13T17:53:52.920 に答える