Некоторые проблемы с расположением строк в ListView - PullRequest
0 голосов
/ 09 сентября 2011

У меня есть следующая очень базовая раскладка для каждой строки ListView. Два TextViews должны быть один поверх другого или, другими словами, в две строки или около того. Тем не менее, я вижу их в одной строке или не вижу их вообще. Также иногда я вижу, что высота рядов очень большая. Может кто-нибудь сказать мне, в чем проблема с моим макетом?

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

    <ImageView
        android:id="@+id/icon"
        android:layout_width="60px"
        android:layout_height="45px"
        android:layout_marginLeft="4px"
        android:layout_marginRight="4px"
        android:layout_marginTop="4px"
        android:src="@drawable/ahsan" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="70px"
        android:layout_y="60px"
        android:text="@+id/TextView01"
        android:textSize="18px" >
    </TextView>

    <TextView
        android:id="@+id/label2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="70px"
        android:layout_y="90px"
        android:text="@+id/TextView02"
        android:textSize="18px" >
    </TextView>

</LinearLayout>

Ответы [ 4 ]

3 голосов
/ 09 сентября 2011

Добавить атрибут android: direction = "vertical" в теге LienarLayout

2 голосов
/ 09 сентября 2011

Скопируйте и вставьте следующий код в макет. Это будет работать.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:padding="5dip" android:layout_height="fill_parent">
    <TextView android:id="@+id/name"
        android:layout_alignParentLeft="true" android:layout_height="40dip"
         android:layout_width="wrap_content"
        android:textSize="18dp" android:text="Name"></TextView>
    <TextView android:id="@+id/phone" android:layout_below="@id/name"
         android:layout_height="40dip"
        android:layout_width="wrap_content" android:textSize="18dp"
        android:text="Name"></TextView>

    <TextView android:layout_width="wrap_content" android:id="@+id/style"
        android:textSize="18dp" android:layout_alignParentRight="true"
        android:layout_height="wrap_content" android:text="Style"
        android:textColor="#0E8C3A" />

<TextView android:id="@+id/icon" android:layout_width="wrap_content"
        android:layout_below="@id/style"  android:text="Style"
        android:layout_height="wrap_content" android:layout_alignParentRight="true"></TextView>
</RelativeLayout>
2 голосов
/ 09 сентября 2011

Попробуйте этот код,

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

<ImageView 
android:id="@+id/icon" 
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/icon" 
android:layout_marginLeft="4px">
</ImageView>
<TextView 
android:text="@+id/TextView01" 
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:id="@+id/label"
android:textSize="18px"
android:layout_toRightOf="@+id/icon"
android:layout_y="60px">
</TextView>

<TextView 
android:text="@+id/TextView02" 
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:id="@+id/label2"
android:textSize="18px"
android:layout_below="@+id/label"
android:layout_toRightOf="@+id/icon">
</TextView>

</RelativeLayout>
2 голосов
/ 09 сентября 2011

Согласно документации для Android ориентация по умолчанию для LinearLayout является горизонтальной, что означает, что ваши ImageView и TextViews находятся в одной строке. Так что слишком большая высота вашей строки вызвана высотой ImageView.

Добавить android:orientation="vertical" к параметрам LinearLayout.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...