Android 滚动视图和线性布局
我试图在Android中获得一个非常简单的布局,但我就是无法让它工作。我想要的只是一个标题(通过Android 滚动视图和线性布局,android,layout,Android,Layout,我试图在Android中获得一个非常简单的布局,但我就是无法让它工作。我想要的只是一个标题(通过包含一个XML文件),然后是一个滚动视图,以显示大量文本,底部有两个按钮,应该总是可见的 我摆弄了LinearLayouts和RelativeLayouts,但不知怎的,我无法让它工作。到目前为止,我所拥有的是: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schema
包含一个XML文件),然后是一个滚动视图
,以显示大量文本,底部有两个按钮,应该总是可见的
我摆弄了LinearLayout
s和RelativeLayout
s,但不知怎的,我无法让它工作。到目前为止,我所拥有的是:
<?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]…是我的按钮所在)
标题在那里,滚动视图弹出,但按钮不见了。您的滚动视图的高度设置为fill\u parent
,这会将滚动视图下方的所有内容从屏幕底部推出。你永远不会看到你无法滚动到的内容。。。请尝试以下模式:
<ScrollView >
<RelativeLayout >
<TextView />
<LinearLayout >
<!-- [ snip ] -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
正如Sam所说,将ScrollView的高度设置为fill_parent可按下屏幕上的按钮。不过,有一种方法可以使用RelativeLayout的布局标记使其工作。试试这个:
<LinearLayout>
[snip]
<RelativeLayout>
<!-- Declare the buttons *before* the ScrollView, but use layout params to move
them to the bottom of the screen -->
<LinearLayout
android:id="@+id/buttonParent"
android:layout_alignParentBottom="true">
[Buttons go here]
</LinearLayout>
<!-- The "android:layout_above" attribute forces the ScrollView to leave space for the buttons -->
<ScrollView
android:height="fill_parent"
android:layout_above="@id/buttonParent" />
[snip]
</ScrollView>
</RelativeLayout>
</LinearLayout>
[剪报]
[按钮在这里]
[剪报]
另一种选择是在框架布局中放置必须留在屏幕上的顶部和底部元素 这个。。[剪]。。这是我的两个钮扣。我希望他们总是在屏幕上,所以在滚动视图之外。我尝试过调整scrollview wrap_内容的高度,但没有效果。好的,使用带有按钮的android:layout_alignParentBottom
将其固定到屏幕底部。尝试过将其放入LinearLayout
中。没有效果。关于你的最后一句话:在上面添加layout_
会导致应用程序崩溃,编舞程序中出现非法状态异常(不管是什么),我似乎明白了。将layout_置于下方
和layout_置于上方
会造成崩溃。奇怪的是,一个有效,另一个无效。显然,它与设置为填充父项的高度有关。这将是一个美好的一天,当我了解Android布局:)。谢谢你的帮助!
<LinearLayout>
[snip]
<RelativeLayout>
<!-- Declare the buttons *before* the ScrollView, but use layout params to move
them to the bottom of the screen -->
<LinearLayout
android:id="@+id/buttonParent"
android:layout_alignParentBottom="true">
[Buttons go here]
</LinearLayout>
<!-- The "android:layout_above" attribute forces the ScrollView to leave space for the buttons -->
<ScrollView
android:height="fill_parent"
android:layout_above="@id/buttonParent" />
[snip]
</ScrollView>
</RelativeLayout>
</LinearLayout>