我试图在 Android 中获得一个非常简单的布局,但我无法让它工作。我想要的只是一个标题(通过 include
一个 XML 文件),然后是一个 ScrollView
以显示大量文本,底部有两个按钮,应该始终可见。
我摆弄过 LinearLayout
和 RelativeLayout
,但不知何故,我无法让它工作。到目前为止,我所拥有的是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/header" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/svDisclaimer"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvDisclaimer">
</TextView>
</ScrollView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/svDisclaimer"
>
.. [ snip ] ..
</LinearLayout>
</RelativeLayout>
</LinearLayout>
( .. [snip] .. 是我的按钮所在的位置) 标题在那里, ScrollView 弹出,但按钮无处可见。
最佳答案
您的 ScrollView 的高度设置为 fill_parent
,这会将 ScrollView 下面的所有内容推离屏幕底部。您将永远看不到无法滚动到的内容...请尝试使用此模式:
<ScrollView >
<RelativeLayout >
<TextView />
<LinearLayout >
<!-- [ snip ] -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
您也可以使用 RelativeLayout 位置标签删除 LinearLayout。 (android:below
、android:toRightOf
等)
尝试使用我评论中的这个配置:
<ScrollView
...
android:above="@+id/buttons" >
...
</ScrollView>
<LinearLayout
android:id="@+id/buttons"
android:layout_alignParentBottom="true"
... >
...
</LinearLayout>
关于android - ScrollView 和线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12789532/