[英]Android - Listview not Scrolling under a ScrollView
這是我的xml文件,顯示了linerlayout和scrollview下的listview。 如何使列表視圖滾動? 因為我想要的是linearlayout下的背景圖像也在滾動。 但是,每當我想滾動列表視圖時,它就會滾動整個布局。
<ScrollView 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"
tools:context=".MainScreenEntered"
>
<LinearLayout
android:layout_width="320dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/mainscreen"
>
<EditText
android:id="@+id/txtSearch"
android:layout_width="220dp"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="130dp"
android:background="@drawable/white"
android:height="10dp"
android:singleLine="true"
android:textSize="15sp"
android:hint="@string/search"
/>
<Button
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="250dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-41dp"
android:background="@drawable/btnsearch"
/>
<ListView
android:id="@+id/lvEntries"
android:layout_width="255dp"
android:layout_height="300dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="41dp"
/>
<Button
android:layout_width="280dp"
android:layout_height="55dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="21dp"
android:background="@drawable/btnaddentry"
android:onClick="goToAddEntryScreen"
/>
</LinearLayout>
</ScrollView>
您不應該將ListView放在ScrollView下。 ListView自身滾動。 相反,您可以將視圖添加為listview的頁眉或頁腳。
報價文件
永遠不要將ScrollView與ListView一起使用,因為ListView負責其自身的垂直滾動。 最重要的是,這樣做會挫敗ListView處理大型列表的所有重要優化,因為它有效地迫使ListView顯示其整個項目列表,以填充ScrollView提供的無限容器。
您還可以使用RelativeLayout
。 僅ListView滾動EditText,而按鈕不滾動。 相應地修改以下內容
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button1"
android:layout_marginTop="81dp"
android:text="Button" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="10" >
<requestFocus />
</EditText>
<ListView
android:id="@+id/listView1"
android:layout_above="@id/button1"
android:layout_below="@id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</ListView>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.