android - 如何在 ScrollView 下方布置辅助固定页脚?

标签 android android-layout scrollview android-relativelayout

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

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

这是我一直在使用的东西。

<?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> 

最佳答案

好的,最后,答案似乎是使用 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>

关于android - 如何在 ScrollView 下方布置辅助固定页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6755151/

相关文章:

android - 用于安卓的 FFmpeg 包装器

android - 与 android :drawableBottom attribute. 结合使用时不显示可绘制形状

Android - 布局重力/宽度相关问题

android - MaterialCardView 崩溃, Material :1. 1.0

android - 如何以编程方式设置 android :button ="@null"?

android - "Big"微调器的滚动条

android - 当 Android 应用程序启动时,Eclipse 不断删除我的 .so 库

php - Android 推送通知 GCM php 和 MySQL

android - 如何使 ScrollView 填充其父级的剩余空间?

scrollview - Sproutcore:在SC.ScrollView中将自定义 View 用作contentView