如何在 ScrollView 下方布局辅助固定页脚?

发布于 2024-11-25 15:48:26 字数 2217 浏览 3 评论 0原文

我正在尝试构建一个具有固定页脚的 Android 布局,其余区域由 ScollView 占据。棘手的地方是,在 ScrollView 的底部,我需要第二个“页脚”,其中有另一个图像,但固定在 ScrollView 的底部,并且位于 ScrollView 后面(并且内容在其上滚动。 ) 这是一个视觉示例

当我使用 RelativeLayout 方法 创建固定页脚时,这是可行的,但它所占用的空间似乎并没有从整个屏幕尺寸中删除。我已经尝试了似乎无穷无尽的方法组合,但我似乎无法想出一种有效的方法。

这是我一直在做的事情。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="top" android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="@drawable/background_image" android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="fill" android:layout_weight="1">
    <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
        <ImageView android:layout_centerHorizontal="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/scroll_footer_image" android:layout_gravity="bottom" android:layout_weight="1"></ImageView>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
            <!-- content for the scrollview goes here. -->
        </LinearLayout>
    </FrameLayout>
</ScrollView>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/footer_background_image" android:layout_alignParentBottom="true">
    <ImageView android:scaleType="centerInside" android:layout_gravity="center"  android:clickable="false" android:src="@drawable/footer_contents" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_weight="0"></ImageView>
</RelativeLayout>
</LinearLayout> 

I'm attempting to build an Android layout that has a fixed footer, with the remaining area taken up by a ScollView. Where this gets tricky is that at the bottom of the ScrollView, I need a second "footer", where there's another image, but but fixed to the bottom of the ScrollView, and which sits behind the ScrollView (and have contents scrolled over it.) Here's a visual example.

When I use the RelativeLayout method to create a fixed footer, that works, but it seems like the space that's taken up by it isn't removed from the overall screen size. I've tried what seems like a seemingly endless combination of methods, and I can't seem to come up with one that works.

Here's what I've been working with.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="top" android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="@drawable/background_image" android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="fill" android:layout_weight="1">
    <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
        <ImageView android:layout_centerHorizontal="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/scroll_footer_image" android:layout_gravity="bottom" android:layout_weight="1"></ImageView>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
            <!-- content for the scrollview goes here. -->
        </LinearLayout>
    </FrameLayout>
</ScrollView>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/footer_background_image" android:layout_alignParentBottom="true">
    <ImageView android:scaleType="centerInside" android:layout_gravity="center"  android:clickable="false" android:src="@drawable/footer_contents" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_weight="0"></ImageView>
</RelativeLayout>
</LinearLayout> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把时间冻结 2024-12-02 15:48:26

好吧,最后,答案似乎是使用 android:layout_gravity 和 android:layout_weight。这似乎对我有用,图像上没有填充。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="@drawable/background_image" android:orientation="vertical">
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:layout_gravity="fill">
    <ImageView android:src="@drawable/scroll_footer_image" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:layout_gravity="bottom"/>
    <ScrollView android:fillViewport="true" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
            <!-- additional content goes here -->
        </LinearLayout>
    </ScrollView>
</FrameLayout>

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="0" android:gravity="bottom">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/footer_topper_image" android:orientation="vertical"/>
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/footer_background_image" android:orientation="vertical" android:gravity="center">
        <ImageView android:src="@drawable/footer_contents" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    </LinearLayout>
</LinearLayout>

Ok, so finally, it appears that answer appears to be to use android:layout_gravity and android:layout_weight. This appears to do the trick for me, with no padding on the images.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="@drawable/background_image" android:orientation="vertical">
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:layout_gravity="fill">
    <ImageView android:src="@drawable/scroll_footer_image" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:layout_gravity="bottom"/>
    <ScrollView android:fillViewport="true" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
            <!-- additional content goes here -->
        </LinearLayout>
    </ScrollView>
</FrameLayout>

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="0" android:gravity="bottom">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/footer_topper_image" android:orientation="vertical"/>
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/footer_background_image" android:orientation="vertical" android:gravity="center">
        <ImageView android:src="@drawable/footer_contents" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    </LinearLayout>
</LinearLayout>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文