mercredi 27 mai 2015

Views in Linear Layout not getting equal space with android:layout_weight attribute

As describe in the topic's title, I have 3 TextView and I would like them to share the whole screen's width using the android:layout_weight attribute, but doing so didn't get the sought results.

LinearLayout:

<TextView
    android:id="@+id/tour1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/back"
    android:clickable="true"
    android:gravity="center"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="8dp"
    android:text="Tour \n disponibili  \n 21" />

<TextView
    android:id="@+id/tour2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_toRightOf="@+id/tour1"
    android:layout_weight="1"
    android:background="@drawable/back"
    android:clickable="true"
    android:gravity="center"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="8dp"
    android:text="Tour \n prenotabili  \n 16" />

<TextView
    android:id="@+id/tour3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_toRightOf="@+id/tour2"
    android:layout_weight="1"
    android:background="@drawable/back"
    android:clickable="true"
    android:gravity="center"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="8dp"
    android:text="Tour \n preferiti  \n 3" />

result in Portrait:

Portrait

result in Landscape:

Landscape

where is the elephant?

ps. As you can notice from the screenshot, a second problem arises: Why the first 2 TextView get stretched in height? How can I fix this unpredictable behavior?

Aucun commentaire:

Enregistrer un commentaire