Android ListView不会扩展整个屏幕 [英] Android ListView doesn't expand the whole screen
问题描述
我遇到的问题类似于此处的问题: Android ListView没有展开整个屏幕?
I've problem similar to the one here: Android ListView doesn't expand the whole screen?
XML是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/ResultLayout">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:layout_width="fill_parent" android:id="@+id/ListView"
android:layout_height="fill_parent"></ListView>
</ScrollView>
<LinearLayout android:id="@+id/pagingPanel"
android:gravity="center" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal"></LinearLayout>
<Spinner android:layout_width="fill_parent" android:id="@+id/ManSpinner"
android:layout_height="fill_parent" />
</LinearLayout>
在这种情况下,我应该有一个ScrollView
,否则PagingPanel
LinearLayout
将会消失.
In this case, I should have a ScrollView
or the PagingPanel
LinearLayout
will disappear.
所需的布局是将所有元素堆叠在一起.但是如果元素超过页面高度,则应在ListView
中添加滚动条.
The desired layout is to have all the elements stacked on top of each other. but if the elements exceed the page height, a scroll should be added to the ListView
.
推荐答案
如果有垂直的LinearLayout
,则LinearLayout
元素的layout_height
不能有多个fill_parent
.您想实现什么布局?统一划分所有元素的屏幕吗?
If you have a vertical LinearLayout
, You can't have multiple fill_parent
for layout_height
of your LinearLayout
elements. What layout you would like to achieve? Uniformly divide screen for all elements?
另一个问题是,在ScrollView
中使用ListView
也不是一个好主意,因为ListView
本身是可滚动的.
Another problem is that using ListView
in ScrollView
is not a good idea also because ListView
itself is scrollable.
您应该写出您想用XML实现的布局.通常,也是一个好习惯,即分多个步骤编写XML,然后逐个布局地迭代解决方案的布局.
You should write what layout you would like to achieve with your XML. Also generally is a good practice to write your XML in multiple steps and iterate to woking solution layout by layout.
好,尝试这样的操作:
Ok, try something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ResultLayout">
<ListView android:id="@+id/ListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout android:id="@+id/pagingPanel"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
<Spinner android:id="@+id/ManSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
这篇关于Android ListView不会扩展整个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!