我尝试实现的布局(我认为)非常简单。
一个 TextView 会根据里面的内容进行扩展。正下方是两个按钮(确定/取消)。
我可以让按钮粘在屏幕底部,效果很好。但我想在 TextView 下方有这些按钮。 我尝试了很多不同的东西,但这是我最新的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView android:id="@+id/Scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
<RelativeLayout android:id="@+id/buttons"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_below="@+id/Scroll"
android:layout_above="@+id/bottom"
>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:id="@+id/ButtonOK"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="OK"
android:layout_weight="1"/>
<Button android:id="@+id/ButtonCancel"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="Cancel"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout android:id="@+id/bottom"
android:layout_height="0px"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
最后的空线性布局是(不成功的)尝试阻止 View 延伸到屏幕底部...
在我尝试的所有操作中,按钮要么位于屏幕底部,要么当 TextView 太大时它们会越过它。
这是我正在尝试做的草图:
最佳答案
目标是否只是拥有一个占据整个页面的可滚动区域减去底部某些按钮占据的数量?
如果是这种情况,您可以在外层使用 LinearLayout
并使用权重:
<LinearLayout
android:layout_height="wrap_content"
orientation="vertical"...>
<ScrollView
android:layout_height="0dp"
android:layout_weight="1"
.../>
<LayoutWithButtons
android:layout_height="wrap_content"
..../>
</LinearLayout>
关于android - 展开 ScrollView 下方的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6065347/