J'essaie d'utiliser une vue vide pour indiquer la couleur de chaque élément dans un ListView. L'idée est que rowColor View est juste une ligne large 3dp qui devrait automatiquement se mettre à la hauteur de secondLine et thirdLine (notez que tout le contenu est défini dans le code, y compris la couleur d'arrière-plan de rowColor et que firstLine et thirdLine sont souvent réglés sur GONE).Android View problème de mise en page de fond
Il apparaît parfaitement dans la disposition graphique d'Eclipse mais rowColor n'apparaît pas du tout sur mon téléphone (sous 2.3.3) et toutes les vues sont empilées. Toute idée de comment résoudre ce problème?
Le code suivant pour list_row a été adopté à partir de here. J'ai fourni tout le code que je pense fonctionne en fonction de cette mise en page, mais pas même proche. Cette disposition fonctionne-t-elle toujours?
list_row.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<TextView
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:singleLine="true"
android:text="First Line" />
<View
android:id="@+id/rowColor"
android:background="#FF0000"
android:layout_width="3dp"
android:layout_height="fill_parent"
android:layout_below="@id/firstLine"
android:layout_alignParentBottom="true" />
<TextView
android:id="@+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/rowColor"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:text="Third Line" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/rowColor"
android:layout_alignParentRight="true"
android:layout_below="@id/firstLine"
android:layout_above="@id/thirdLine"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:singleLine="true"
android:text="Second Line" />
</RelativeLayout>
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Activité ListViewTest.java ici: http://pastie.org/2035822
Merci.
Peut-être essayer "wrap_content", voir ce que cela fait – Austin
Est-ce que ça se voit? ou est-il seulement manquant quand firstList est GONE – jkhouw1
Eh bien rowColor n'a jamais réellement de contenu, juste une couleur de fond. Il n'apparaît pas pour wrap_content ou match_parent, ou lorsque firstLine est GONE. Je le vois seulement quand j'ai sa taille réglée à une taille de 40dp. – kevin