Android:如何向全屏 ScrollView 添加页脚?

标签 android scrollview footer android-relativelayout bottom-up

我希望页脚锚定在屏幕底部当且仅当它可以锚定在那里而不与任何其他 View 重叠时。

问题是我不知道要将多少 View 添加到页眉或页脚。

如果将页脚放在窗口底部会使其重叠,我想将页脚放在 ScrollView 的底部。 (也许通过将它添加到 RelativeLayout 并规定它需要位于顶部组件下方?)

这是我想要得到的图片:

desired result

地点:

1)RelativeLayout既包含顶部的TableLayout,也包含底部的LinearLayout。

2)TableLayout 随着 TableRows 的添加而向下扩展。

3) 当向其添加 View 时,LinearLayout 从底部向上展开。

~~~

我希望 ScrollView 的大小增长到足以适应组件而不重叠。

在此先感谢如此出色的社区支持

最佳答案

我认为你可以用线性布局来解决它。您在线性布局中设置了三个 block :页眉、正文、页脚。将 body 设置为 fill_parent 和 layout_weight=1,这样 body 将扩展以填充 header 和 footer 从 parent 中取出后剩下的部分。整个结构放入 ScrollView。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TableRow><TextView android:text="Text1"/></TableRow>
            <TableRow><TextView android:text="Text2"/></TableRow>
        </TableLayout>
        <RelativeLayout 
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView 
                android:text="@string/lorem_ipsum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </RelativeLayout>
        <LinearLayout 
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
                android:text="Text3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:text="Text4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

我在 Android 2.1 的 Emulator 中对此进行了测试,看起来它可以工作。

关于Android:如何向全屏 ScrollView 添加页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7134085/

相关文章:

css - 无法在wordpress中更改页脚颜色

html - 使装饰 div 的边框向下延伸到粘性页脚的顶部

CSS 宽度行为奇怪

java - 在Android项目中创建一个类

android - 在 Android 中,如何更改自动完成,使其在单个字符而不是 2 个字符后开始?

android - 从服务器 RPC :s-7:AEC-0 检索信息时出错

android - 如何检查用户是否已授予相机或位置权限(android)UNITY

ScrollView 中的 Android LinearLayout

javascript - 使 TouchableOpacity 在开始滚动时不突出显示元素 [React Native]

listview - Flutter:ListView不可滚动,不可弹跳