【发布时间】:2015-01-23 19:04:02
【问题描述】:
我已经开始构建一个应用程序,其中有两个 ListView 在彼此下方。
现在我在它上面放了一个 ScrollView,因为它的数量可能会变得非常大,因此我希望整个布局是可滚动的,而不是列表本身。但我的解决方案不起作用!
顺便说一句:我不想用 LinearLayout 替换我的 ListViews,因为那样我所有的适配器都不见了。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 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"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/Heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ListView1" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
style="@style/ButtonStyle.SpinnerAddButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_add_black_24dp"
android:onClick="addToList1" />
</LinearLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginLeft" />
<!--Second list-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/Heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ListView2" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
style="@style/ButtonStyle.SpinnerAddButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_add_black_24dp"
android:onClick="addToList2" />
</LinearLayout>
<ListView
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginLeft" />
</LinearLayout>
</ScrollView>
我的布局现在显示彼此下的所有 ListView,但每个 ListView 仅显示一个项目,然后您可以滚动浏览此列表。
【问题讨论】:
-
将可垂直滚动的内容放在
ScrollView中很难做到。我强烈建议您提出不同的 UI,例如在ViewPager中使用两个页面,每个列表+按钮对一个。 -
ScrollView+ListView+ListView= 坏事会发生。 -
一个在另一个可滚动对象中的可滚动对象确实是一个最糟糕的设计 UI。
-
感谢您的建议,我不得不说这不是一个坏主意,但也许有人对我有不同的选择:-D
-
好的,我认为 3 种意见可以说服我摆脱当前的 UI
标签: android listview android-listview scroll