【发布时间】: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