【发布时间】:2012-11-29 23:48:11
【问题描述】:
我的layout 包含一个包含所有内容的ScrollView。在某些时候,我需要在屏幕底部显示一个ViewScrollView 的顶部(上方)(所以ScrollView 位于View 的后面),这样我就可以向上滚动屏幕并向下,而这个View 仍然粘在设备的屏幕底部。请建议大家如何做这样的layout。谢谢。
【问题讨论】:
我的layout 包含一个包含所有内容的ScrollView。在某些时候,我需要在屏幕底部显示一个ViewScrollView 的顶部(上方)(所以ScrollView 位于View 的后面),这样我就可以向上滚动屏幕并向下,而这个View 仍然粘在设备的屏幕底部。请建议大家如何做这样的layout。谢谢。
【问题讨论】:
如果您希望滚动视图位于视图后面,可以这样做:
(来自this SO question的部分代码副本)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/RelativeLayout1">
<ScrollView android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ScrollView>
<View android:id="@+id/bottomView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">>
</View>
</RelativeLayout>
滚动视图现在将扩展到视图元素之外。
【讨论】:
您可以创建两个片段并使用权重属性来分配空间。顶部的片段将承载您的根 scrollView,而底部的片段将拥有视图。
【讨论】:
好的,两个选项,第一个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<View
android:id="@+id/myView"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/myView" />
</RelativeLayout>
这样您的ScrollView 将始终高于您的View。但似乎您希望 ScrollView 填满整个屏幕,而 View “隐藏”您的 SV 的某些项目。所以检查这段代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<View
android:id="@+id/myView"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
【讨论】:
View wrap_content 将始终填满整个屏幕。请不要问我为什么,但这就是我所经历的......