我有一个自定义对话框,其布局如下:
<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>
Run Code Online (Sandbox Code Playgroud)
我的问题是滚动视图是当滚动视图中的文本太多时,下面的按钮会从对话框中向下推.我已经能够通过使用android:layout_alignParentBottom ="true"将包含按钮的RelativeLayout锚定到底部来阻止它,但是当滚动视图中的文本较少时,我将整个对话框拉伸到屏幕底部我不希望这样.
我怎样才能获得这样的布局:
[SOME TEXT]
[Scrollable region]
[Buttons]
Run Code Online (Sandbox Code Playgroud)
尝试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"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3273 次 |
| 最近记录: |