Comment flotter des images directement dans Android relativelayout?
-
13-11-2019 - |
Question
Je veux afficher un texte et à côté du texte un nombre dynamique d'images qui doivent être flottées vers le côté droit.
C'est ce que j'ai:
<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>
Mon problème est que si icon1
n'est pas visible (je contrôle sur mon code java) icon2 ne s'affiche plus sur le côté droit. Il a recouché text1
, parce que le référencé icon1
est manquant.
La solution
Eh bien, soit votre mise en page ci-dessus est incomplète (et si c'est le cas, vous devez publier la chose complète), soit vos identifiants sont cassés (vous avez présenté icon2
à gauche de @+id/1
Quand ça devrait être à gauche de @+id/icon1
.
Essayez de régler android:layout_alignWithParentIfMissing="true"
sur icon2
et corriger les ID de mise en page.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow