【发布时间】:2015-03-01 00:14:30
【问题描述】:
我无法显示两个连续的全尺寸(高度)ListViews,它们不能单独滚动,只能通过滚动根元素来滚动。
这件事整天困扰着我,因为我有各种输出(两个可滚动列表视图、半切滚动视图等)但没有一个成功。阅读之前的帖子here、here 和here。
为您提供当前的布局 xml,有什么解决方案?删除ScrollView,将LinearLayout改为RelativeLayout,设置layout_weight?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<xxx.xxx.xxx.xxx.MultiSpinner
android:id="@+id/ad_list_filter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
/>
<xxx.xxx.xxx.xxx.MultiSpinner
android:id="@+id/ad_list_sort"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
/>
</LinearLayout>
<ListView
android:id="@+id/adListInterests"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:divider="@null"
android:dividerHeight="5dp"
>
</ListView>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ad_list_seperator"
/>
<ListView
android:id="@+id/adListNoninterests"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:divider="@null"
android:dividerHeight="5dp"
>
</ListView>
</LinearLayout>
</ScrollView>
提前致谢!
编辑:
删除建议的ScrollView 后会生成两个可滚动列表。根据 cmets 的说法,我会尝试使用提供的插件来实现它,但是我仍然希望找到仅基于修改布局代码的解决方案。感谢您的时间!
图片:
布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<xxx.xxx.xxx.xxx.MultiSpinner
android:id="@+id/ad_list_filter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
/>
<xxx.xxx.xxx.xxx.MultiSpinner
android:id="@+id/ad_list_sort"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
/>
</LinearLayout>
<ListView
android:id="@+id/adListInterests"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:divider="@null"
android:dividerHeight="5dp"
>
</ListView>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ad_list_seperator"
/>
<ListView
android:id="@+id/adListNoninterests"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:divider="@null"
android:dividerHeight="5dp"
>
</ListView>
</LinearLayout>
【问题讨论】:
-
Removal of ScrollView强烈推荐(这确实是一种更糟糕的做法)。ListViews that would not be scrollable individually but only by scrolling the root element是什么意思?也许,您可以重新考虑您的 UI 以使用ExpandableListView(父/子关系)? -
@DerGolem 只是想说列表应该完全显示并且滚动必须在 ScrollView 上发生。
-
您是否知道将 ListView(或任何其他 scrollable)放入 ScrollView(或任何其他 scrollable)是一个错误 想法?
-
是的。之所以如此,是因为当滚动事件被触发时,使用哪个视图“混淆” -
ScrollView或ListView。 -
是的,滚动中存在“冲突”。我也认为有一定的 CPU 开销。
标签: android android-layout android-listview