ListView控件以弥补Android的整个屏幕 [英] ListView to cover entire screen in Android
问题描述
我在我的Android应用程序(API 8)实施的列表视图。然而,该列表仅包括三个要素,因此,超过一半的屏幕的是空的。我想扩大列表视图覆盖了手机的整个屏幕。有哪些方法做同样的?
I have implemented a listview in my Android app (API 8). However, the list consists of only three elements and hence, more than half of the screen is empty. I want to expand the listview to cover the entire screen of the phone. What are some ways to do the same?
下面是我的布局XML文件:
Here is my layout XML file:
<?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="match_parent"
android:orientation="vertical"
android:background="@color/white"
android:shape="rectangle"
android:paddingTop="5dp"
android:paddingBottom="0dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
>
<ImageView
android:layout_weight="40"
android:id="@+id/test_image"
android:layout_width="158dp"
android:layout_height="52dp"
android:contentDescription="@string/footer"
android:src="@drawable/logo1" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="127dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="60"
android:prompt="@string/city_prompt"
/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:id="@android:id/list"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:drawSelectorOnTop="true"
android:layout_gravity="center"
android:dividerHeight="2dp"
/>
</LinearLayout>
</LinearLayout>
请注意,我想列表项,以覆盖整个屏幕,在地方只有三个项目。
Please note that I want the list items to cover the entire screen, with just three items in place.
推荐答案
我刚刚复制的XML,粘贴和尝试,并能正常工作。还有一件事要告诉的是,你不应该使用 layout_height =WRAP_CONTENT
。相反,你可以把它作为的android:layout_height =0dip
因为你已经使用的android:layout_weight =1
这将使ListView的填补你的LinearLayout的剩余区域。
I just copied your XML, pasted and tried, and it works fine. One more thing to tell is that you should not use layout_height="wrap_content"
. Instead you can give it as android:layout_height="0dip"
as you have already used android:layout_weight="1"
which will make ListView fill the remaining area of your LinearLayout.
这篇关于ListView控件以弥补Android的整个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!