我希望页脚锚定在屏幕底部当且仅当它可以锚定在那里而不与任何其他 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 中对此进行了测试,看起来它可以工作。
我是一名优秀的程序员,十分优秀!