我有一个相对 View ,它有两个 subview ,一个 ScrollView 和一个按钮,现在我想这样做:我希望这个 View 包装它的内容,不留出空白空间,也不超过屏幕尺寸。 我怎样才能做到这一点?谁能帮忙?
这是我当前无法使用的布局文件。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
</ScrollView>
<Button
android:id="@+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/content"
... />
</RelativeLayout>
最佳答案
RelativeLayout
没有这种可能性。但是 LinearLayout
可以。只需将LinearLayout
的android:orientation
设置为vertical
,设置ScrollView
的android:layout_weight
到 1
,它应该可以工作了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ScrollView>
<Button
android:id="@+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
关于android使 View 包装内容但不大于特定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40842448/