[英]how to make scrollable ListView but not to fill whole screen?
我想在頂部(標題)制作帶有TextView的屏幕,中間是ListView,底部是按鈕。 如何放置ListView,將填充頂部TextView和底部按鈕之間的整個空間,並能夠滾動其內容?
現在,當我的列表增長時,它會按下屏幕外的底部按鈕。
我有:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button android:id="@+id/button1"
android:layout_height="wrap_content"
android:text="Button"
android:layout_width="wrap_content"
/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_alignParentBottom="true"
/>
<ListView android:id="@+id/lvLocations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
<Button android:text="LayerDrawable"
android:id="@+id/button5"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="@drawable/layer_drawable"
/>
</LinearLayout>
最后一個TextView
用於創建間隙並將Button
移動到底部。
使用LinearLayout
。 使用layout_height="fill_parent"
將layout_weight="1"
為ListView
。 去除其他元素的重量。
<ListView android:id="@+id/lvLocations"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
></ListView>
<?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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:text="arg0"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:textStyle="bold"/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/prevButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Previous"
android:layout_weight="1"/>
<Button
android:id="@+id/nextButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
這正是我設置的方式,而且效果很好。
您可以使用android:layout_below =“”和android:layout_above =“”的幫助來實現所需的結果。 希望這可以幫助。
將所有元素包裝在布局中 : LinearLeyout或RelativeLayout 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.