ListView не отображается в Android

1

Я новичок в разработке приложений для Android.

это мой файл макета xml.

<?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="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button 
    android:layout_weight="0.5"
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/cancel"/>

<Button 
    android:layout_weight="0.5"
    android:layout_gravity="right"
    android:id="@+id/editall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/editall"/>
</LinearLayout>
<ListView 
    android:id="@android:id/list"
    android:cacheColorHint="#00000000"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:fadingEdge="none"/>
</LinearLayout>

В этом я могу видеть кнопки, но просмотр списка не отображается. Может любое тело помочь мне пожалуйста. заранее спасибо

Теги:
android-layout

3 ответа

4
Лучший ответ

просто замените wrap_content вместо fill_parent на кнопку linear Layout.

изменить на

<?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="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button 
    android:layout_weight="0.5"
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/cancel"/>

<Button 
    android:layout_weight="0.5"
    android:layout_gravity="right"
    android:id="@+id/editall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/editall"/>
</LinearLayout>
<ListView 
    android:id="@android:id/list"
    android:cacheColorHint="#00000000"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:fadingEdge="none"/>
</LinearLayout>
  • 0
    спасибо, я не видел этого. Спасибо за помощь.
  • 0
    И вы можете рассмотреть возможность размещения android:layout_height="fill_parent" для ListView, чтобы он android:layout_height="fill_parent" все оставшееся пространство
0

Вы также установили Adapter для своего ListView в свой onCreate()? Ничего не будет показано на экране, если оно пустое, так как вы также установили прозрачный фон с использованием cacheColorHint и применили к нему контейнер wrap_content height.

0

Измените внутреннюю линейную высоту макета от fill_parent до wrap_content.

Поскольку придание высоты fill_parent будет охватывать всю высоту родителя, которая скроет список

Ещё вопросы

Сообщество Overcoder
Наверх
Меню