我有一个自定义对话框,其布局如下:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mylayout">
<LinearLayout
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView ... />
<TextView .../>
</LinearLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title">
<LinearLayout ...>
<TextView ...
android:text="lots of text........" />
<TextView .../>
</LinearLayout>
</ScrollView
<RelativeLayout ...
android:layout_below="@+id/scrollView">
<Button ...>
<Button ...>
</RelativeLayout>
</RelativeLayout>
我的问题是滚动视图是当滚动视图中有太多文本时,下面的按钮会被推到对话框之外。我已经能够通过使用 android:layout_alignParentBottom="true" 将包含按钮的relativelayout锚定到底部来防止它,但是当滚动视图中的文本较少时,我将整个对话框拉伸到屏幕底部,并且我不想要这样。
我怎样才能得到这样的布局:
[SOME TEXT]
[Scrollable region]
[Buttons]
Try LinearLayout
而不是RelativeLayout
将按钮放在单独的布局中,并在按钮布局上施加权重。
LinearLayout - top level start, android:layout_weight="0"
LinearLayout with TextViews embeded, android:layout_weight="1"
LinearLayout with ScrollView embeded, android:layout_weight="1"
LinearLayout with Buttons embeded, android:layout_weight="1"
LinearLayout - top level finish, android:layout_weight="0"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)