layout applications - empiler deux TextViews verticalement, à l'intérieur d'une rangée ListView

StackOverflow https://stackoverflow.com/questions/4566909

Question

J'ai commencé avec Fedor de ListView mise en œuvre . Voici le XML pour mon élément ListView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
      android:id="@+id/image"
      android:layout_width="50dip"
      android:layout_height="50dip" android:src="@drawable/stub" android:scaleType="centerCrop"/>
<TextView
      android:id="@+id/name"
      android:layout_width="0px"
      android:layout_height="0px"
      android:layout_weight="0" android:textSize="20dip" android:layout_marginLeft="10dip"/>
<TextView
      android:id="@+id/address"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"  android:textSize="16dip" android:layout_marginLeft="10dip"/>

</LinearLayout>

Ce que je vois sur mon appareil est le ImageView et les deux TextViews affichées en séquence de gauche à droite.

Ce que je veux est le ImageView tout le chemin à droite (ce qui est déjà correct), le nom TextView à droite de la imageview (ce qui est correct), et la TextView adresse, sous le nom TextView. Je n'ai pas été en mesure de comprendre comment obtenir ce bien aménagé.

S'il vous plaît noter, je sais que je pourrais ajouter une nouvelle ligne au nom et à inclure le texte d'adresse après, mais je veux ces deux éléments ont différentes tailles de police, de sorte que ce n'est pas une option. Merci beaucoup!

Était-ce utile?

La solution

Vous devez définir l'orientation du LinearLayout et de réaliser ce que vous voulez faire, vous aurez besoin d'utiliser plusieurs de ceux-ci. En pseudo-code, vous devez faire:

<LinearLayout
    android:orientation="horizontal"
    ...>
    <ImageView
        android:id="@+id/image"
        ... />
    <LinearLayout
        android:orientation="vertical"
        ...>
        <TextView
             android:id="@+id/name"
             ...>

        <TextView
             android:id="@+id/address"
             ...>
    </LinearLayout>
</LinearLayout>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top