gpt4 book ai didi

android - 将 View 添加到 ScrollView 内的布局底部

转载 作者:IT老高 更新时间:2023-10-28 13:18:28 26 4
gpt4 key购买 nike

所以我的布局基本上是这样的:

<ScrollView>
<RelativeLayout>
<BunchOfViews/>
<ImageView android:layout_alignParentBottom="true"/>
</RelativeLayout>
</ScrollView>

我有 ScrollView 所以无论屏幕的高度如何,所有的布局总是可见的。问题是在非常高的屏幕上,我仍然希望我的 ImageView 位于底部。但是,ScrollView 的子项似乎没有定义的底部。 View 放置在布局的顶部。我怎样才能巧妙地解决这个问题?

最佳答案

我遇到了同样的问题。我从来没有找到一个非常令人满意的解决方案,但我是这样做的。也许别人有更好的方法,我讨厌添加什么都不做的布局。

我的 hack 是在 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>

关于android - 将 View 添加到 ScrollView 内的布局底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2417221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com