Android列表视图项高度fill_parent不起作用

时间:2023-02-09 21:13:50

I have an android app with a mainactivity that contain a listview, this is the code of the main activity layout:

我有一个带有main活动的Android应用程序,其中包含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="fill_parent"
    android:orientation="vertical" >

    <ListView  android:id="@+id/commandList" 
               android:layout_width="fill_parent"
               android:layout_height="0dp"
               android:layout_weight="1"
              />

</LinearLayout>

in the listview I display a partial view, this is the code of view layout:

在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"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/commandText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />

</LinearLayout>

I wish that the elements would fill the height of mainactivitylayout but the result is this: result imageAndroid列表视图项高度fill_parent不起作用

我希望元素填充mainactivitylayout的高度,但结果是:结果图像

thank you regards

谢谢你的问候

1 个解决方案

#1


5  

Waqas is right in above comment. (It totally kills the purpose of using ListView)

Waqas在上述评论中是正确的。 (它完全杀死了使用ListView的目的)

But still you want to implement this then in getView() of adapter try below code

但是你仍然希望实现这个,然后在适配器的getView()尝试下面的代码

convertView.getLayoutParams().height = parent.getHeight() / NO_OF_ITEMS;
convertView.requestLayout();

#1


5  

Waqas is right in above comment. (It totally kills the purpose of using ListView)

Waqas在上述评论中是正确的。 (它完全杀死了使用ListView的目的)

But still you want to implement this then in getView() of adapter try below code

但是你仍然希望实现这个,然后在适配器的getView()尝试下面的代码

convertView.getLayoutParams().height = parent.getHeight() / NO_OF_ITEMS;
convertView.requestLayout();