【问题标题】:How can I layout a secondary fixed footer, underneath a ScrollView?如何在 ScrollView 下方布局辅助固定页脚?
【发布时间】:2011-07-19 23:03:59
【问题描述】:

我正在尝试构建一个具有固定页脚的 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> 

【问题讨论】:

  • 我找到了一种可能的解决方案。由于我正在处理的固定页脚是基于图像的,因此我在滚动页脚中添加了空白空间。我现在有一个带有滚动页脚图像的 FrameLayout 和其中的滚动视图,以及一个用于固定页脚的单独 LinearLayout,所有这些都包含在一个 RelativeLayout 中。我不太喜欢处理这样的图像,所以我仍然有兴趣看看是否还有其他解决方案。
  • 哦,那个解决方案留下了 FrameLayout 和它的 ScrollView,它位于固定页脚后面,留下了不可读的内容。

标签: android android-layout scrollview android-relativelayout


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 2012-01-23
    • 2018-01-27
    • 2019-10-29
    • 2011-01-02
    • 1970-01-01
    相关资源
    最近更新 更多