如何让ListView行填满屏幕?
我有我在片段中创建的这个ListView。该列表具有动态内容,我希望列表填充所有屏幕时,只有很少的条目。 如何做到这一点?如何让ListView行填满屏幕?
下面是相关的XML文件,myFragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listview"
android:layout_height="wrap_content"
android:layout_width="match_parent" >
</ListView>
</LinearLayout>
,这里是listview_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_height="fill_parent"
android:layout_width="fill_parent" >
<TextView
android:id="@+id/FirstText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/SecondText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#FFC030"
android:layout_weight="2">
</TextView>
<TextView
android:id="@+id/ThirdText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/FourthText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</TextView>
</LinearLayout>
编辑: 换句话说这里我的(多列)ListView in a Fragment(标签活动):
,我想这样的结果:
<ListView
android:id="@+id/listview"
android:layout_height="match_parent"
android:layout_width="match_parent" >
</ListView>
设置的ListView的高度match_parent像我在上面所做的。
更新:
在你的片段类,得到的屏幕(编程)的高度,那么当您设置您需要设置的LinearLayout
(内listview_row.xml
)的高度ListView
适配器到你得到的屏幕高度。
OR
集LinearLayout
的高度,就像我在下面设置了一些随机值(不推荐,因为屏幕的高度不同分辨率的屏幕变化)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_height="500dp"
android:layout_width="fill_parent" >
<TextView
android:id="@+id/FirstText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/SecondText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#FFC030"
android:layout_weight="2">
</TextView>
<TextView
android:id="@+id/ThirdText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/FourthText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</TextView>
</LinearLayout>
它不起作用,因为我想改变每一行的高度来制作完整的listview套装屏幕尺寸,而不仅仅是listview的layout_height ... – smartmouse 2014-10-06 09:36:53
如果您做了任何更改,您是否可以在问题中更新您的代码? – Harsha 2014-10-06 09:41:00
我没有做任何改变... – smartmouse 2014-10-06 09:42:24
我想我已经看到了这个图像在web上:) – 2014-10-06 08:48:05
你的意思是'mathch_parent'为'android:layout_height'或者你想要改变每一行的高度吗? – 2014-10-06 09:12:20
@PareshMayani你是对的!我在编辑你的代码:)谢谢你的分享! – smartmouse 2014-10-06 09:33:00