所以我的布局基本上是这样的:
<ScrollView>
<RelativeLayout>
<BunchOfViews/>
<ImageView android:layout_alignParentBottom="true"/>
</RelativeLayout>
</ScrollView>
我有ScrollView
,所以无论屏幕的高度如何,所有的布局都是可见的。问题是,在一个非常高的屏幕上,我仍然希望我的ImageView
在底部。然而,ScrollView
的子类似乎没有定义好的底部。View
被放置在布局的顶部。我怎样才能以一种整洁的方式解决这个问题?
发布于 2010-03-10 23:13:49
我遇到了同样的问题。我从来没有找到一个非常令人满意的解决方案,但以下是我是如何做到的。也许其他人有更好的方法,我讨厌添加不做任何事情的布局。
我的诀窍是在scrollview
的底部添加一个虚拟的linearlayout
,让fill_parent
占据所有的空间,并迫使scrollview
充满屏幕。然后将我想要的任何组件添加到该linearlayout
中。
这是我的一个布局,可以做到这一点:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="15px" >
<!-- bunch of components here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/spinner"
android:layout_marginTop="5px"
android:gravity="center_horizontal|bottom"
android:paddingTop="2px" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20px"
android:paddingRight="20px"
android:text="Delete" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
发布于 2010-11-24 00:46:04
我遇到了同样的问题,并找到了这个页面:
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
基本上,您将ScrollView的android:fillViewport
设置为true,这将允许子视图扩展到与ScrollView本身相同的高度,从而填充空间。然后,您只需要将其中一个子控件的layout_height
设置为fill_parent
,并将layout_weight
设置为1
,从而使该控件“弹簧”来填充空白空间。
请注意,如果ScrollView的内容已经足够填充ScrollView,则android:fillViewport
不起作用,因此该设置仅在需要时生效。
我的最终XML如下所示:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_height="fill_parent"
android:layout_weight="1">
<!-- this expands to fill the empty space if needed -->
</LinearLayout>
<!-- this sits at the bottom of the ScrollView,
getting pushed out of view if the ScrollView's
content is tall enough -->
<ImageView
android:layout_height="wrap_content"
android:src="@drawable/footer_image">
</ImageView>
</LinearLayout>
</ScrollView>
发布于 2010-06-17 19:52:08
看起来linearlayout
不是必须的,重要的是fillViewPort
。你可以直接使用
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottomParent="true">
现在您已经将relativelayout
指定为至少是屏幕的大小。
https://stackoverflow.com/questions/2417221
复制相似问题