[英]Not able to scroll LinearLayout which contain a line graph and a spinner inside a ScrollView
[英]scroll ListView inside a LinearLayout which is wrapped in ScrollView
我有一個應該可以滾動的活動,因此我用ScrollView將其包圍。 我在那里有兩個listViews,我不想顯示所有項目都需要它那么大。
如果我可以設置maxHeight屬性,那將是很好的選擇,以便在只有2個項目的情況下不存在空白空間,但是如果有50個項目,我一次只希望看到其中5個項目。 不幸的是沒有這種屬性,所以我決定將高度設置為固定數字。 任何建議如何更正確地做到這一點將不勝感激。
但是主要的問題是,當我嘗試滾動listViews之一時,整個LinearLayout都會向下滾動。 (如果我在滾動列表時用另一根手指將LinearLayout固定在適當的位置,則可以避免這種情況,但這當然不是解決方案。)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.ballmaschine.pages.SettingsPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Some other stuff here -->
<TextView
android:text="Eine Maschine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:layout_marginTop="8dp" />
<ListView
android:layout_width="match_parent"
android:id="@+id/lvCalibsM1"
android:layout_height="200dp" />
<TextView
android:text="Zwei Maschinen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:layout_marginTop="8dp" />
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/lvCalibsM2"/>
<!-- Some more stuff here -->
</LinearLayout>
將此添加到ListView
android:scrollbars = "none"
而這在Java代碼中
listView.setNestedScrollingEnabled(false)
在這些情況下,請始終嘗試NestedScrollView並將其添加到該行中
app:layout_behavior="@string/appbar_scrolling_view_behavior"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.