【发布时间】:2012-01-08 13:14:31
【问题描述】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/bag"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relativeLayout2"
style="@style/relbag"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView style="@style/CodeFont"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="18dp"
android:textSize="15dp"
android:text="General Preference"
android:id="@+id/genpref">
</TextView>
<ListView
android:id="@+id/settingsListView1"
style="@style/listbag"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:background="@drawable/radius"
android:listSelector="@drawable/list_selector"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:scrollbars="none"
android:layout_below="@id/genpref"/>
<TextView style="@style/CodeFont"
android:id="@+id/notpref"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:textSize="15dp"
android:text="Notification Preference"
android:layout_below="@id/settingsListView1">
</TextView>
<ListView style="@style/listbag" android:id="@+id/settingsListView2" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dip" android:layout_marginRight="15dip"
android:layout_marginBottom="15dip"
android:background="@drawable/radius"
android:paddingLeft="5dip" android:paddingRight="5dip"
android:paddingTop="15dip" android:paddingBottom="15dip"
android:listSelector="@drawable/list_selector"
android:layout_below="@id/notpref"
android:scrollbars="none"
/>
</RelativeLayout>
</LinearLayout>
在我的应用程序中,我想在线性布局中创建两个列表视图,并使线性布局可滚动而不使用 ScrollView。据我阅读,滚动视图在使用列表视图时存在问题。这张图片不是我想要的,但让我们假设在 listview 的下方还有另一个 listview。所以我想显示列表视图的所有可用项目(在我的应用程序 2 列表视图的项目中)并使 LinearLayout 可滚动。 ScrollView 并不顺利,因为它必须只有一个直接子级。我找不到解决方案。所以请帮我解决,谢谢
【问题讨论】:
-
我见过其他类似的问题,但不明白为什么人们要显示
ListView并显示所有可用的列表项。ListView(以及它的滚动能力)的全部意义在于它旨在适应屏幕(或部分屏幕),并且可以滚动以显示无法适应其占据的空间的其他项目。如果您想显示“项目”序列,只需为项目创建一个视图,然后动态创建多个项目,将它们动态插入ScrollView,然后忘记使用ListView。 -
推荐stackoverflow.com/a/17876855/336990 ...可能有用
标签: android