Android: элементы списка, фиксированный макет - PullRequest
2 голосов
/ 27 ноября 2011

У меня проблема с макетом.Что странно, я не мог найти решение онлайн.Может быть, кто-то здесь хотел бы помочь мне?Я хотел бы отобразить такой список:

enter image description here

Но все, что я могу получить, это:

enter image description here

Вот мойXML-код для элемента списка:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <ImageView android:id="@android:id/icon" android:layout_width="22px"
        android:layout_height="22px" android:layout_marginLeft="4px"
        android:layout_marginRight="10px" android:layout_marginTop="4px"
        android:src="@drawable/icon" />

    <TextView android:id="@android:id/text1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginLeft="4px"
        android:layout_marginRight="10px" android:textSize="20px" />

    <TextView android:id="@android:id/text2" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginLeft="4px"
        android:layout_marginRight="10px" android:textSize="20px" 
        android:layout_alignParentRight="true" 
        android:layout_weight="0.4" />

</LinearLayout>

Буду признателен за помощь, спасибо;)

1 Ответ

5 голосов
/ 27 ноября 2011

Используйте RelativeLayout в приведенном выше коде, не линейное, потому что android:layout_alignParentRight="true" работает только относительно, а не линейно.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <ImageView android:id="@android:id/icon" android:layout_width="22px"
        android:layout_height="22px" android:layout_marginLeft="4px"
        android:layout_marginRight="10px" android:layout_marginTop="4px"
        android:src="@drawable/icon" />

    <TextView android:id="@android:id/text1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginLeft="4px"
        android:layout_marginRight="10px" android:textSize="20px" />

    <TextView android:id="@android:id/text2" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginLeft="4px"
        android:layout_marginRight="10px" android:textSize="20px" 
        android:layout_alignParentRight="true" 
        android:layout_weight="0.4"
        />

</RelativeLayout>
...