Android底部按钮栏&;带对话框主题的滚动视图
我正在尝试通过以下方式显示Android活动:Android底部按钮栏&;带对话框主题的滚动视图,android,dialog,scrollview,buttonbar,Android,Dialog,Scrollview,Buttonbar,我正在尝试通过以下方式显示Android活动: 对话主题 固定在对话框顶部的标题 固定在对话框底部的按钮栏 中间的滚动视图。 我写的布局符合这些标准,除了对话框总是充满整个屏幕(见底部的垂直屏幕截图) 这是我的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_w
- 对话主题李>
- 固定在对话框顶部的标题李>
- 固定在对话框底部的按钮栏李>
- 中间的滚动视图。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/header"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp"
android:gravity="center_vertical"
android:textSize="18dip" android:textColor="#ffffff"
android:text="Sample Layout" />
<LinearLayout android:id="@+id/controls" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="@android:style/ButtonBar">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="Yes" />
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="No" />
</LinearLayout>
<ScrollView android:id="@+id/test" android:layout_below="@id/header"
android:layout_above="@id/controls"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginBottom="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Integer dui odio, convallis vitae suscipit eu,
tincidunt non mi. Vestibulum faucibus pretium purus vel adipiscing.
Morbi mattis molestie risus vitae vehicula. [...]" />
</ScrollView>
</RelativeLayout>
此外,活动的样式为@android:style/Theme.Dialog
和android:windowNoTitle
我不太明白为什么这个布局会扩展到整个屏幕。没有一个视图的布局高度设置为fill_parent
;父布局也没有设置为fill\u parent
有人知道我想做的是可能的吗?如果有,怎么做
水平模式下的当前布局
垂直模式下的当前布局
我认为,因为您给了android:layout\u alignParentBottom=“true”线性布局,所以按钮会移动到底部,看起来是这样的 所以最好删除android:layout\u alignParentBottom=“true”并使用android:layout\u marginTop=“一些值”
请试试这个..谢谢..我有一个与你的活动非常相似的活动。我很久以前就做过了,所以我真的不记得我为什么要做这个和那个,但我想我实现了你想要做的。这是我的密码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="bottom"
android:background="@color/color2">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/color1">
<TextView
android:id="@+id/infos_titre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="12dip"
android:textSize="20dip"
android:textColor="@color/color2"
android:gravity="center"
android:background="@color/color1">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/infos_LL"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="@+id/infos_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16dip"
android:padding="4dip"
android:textColor="@color/color1"
android:lineSpacingMultiplier="1.1"
android:autoLink="web">
</TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/color1"
android:paddingTop="6dip">
<Button
android:id="@+id/infos_remarquebutton"
android:text="Faire une remarque"
android:drawableLeft="@drawable/happy"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textColor="@color/buttontext_color">
</Button>
<Button
android:id="@+id/infos_partagerbutton"
android:text="Partager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_menu_share"
android:layout_weight="1"
android:textColor="@color/buttontext_color">
</Button>
</LinearLayout>
不要被法式英语的纳明语打扰
所以,我认为主要的技巧是将ScrollView放在线性布局中。我也给了线性布局1的权重(我不记得为什么…)。
另外,顶部布局是线性布局,不像代码中那样是相对布局,但我认为它不会改变任何东西,尽管我不熟悉相对布局
希望有帮助 仅删除alighParentBottom不起作用。结果是按钮栏移动到对话框的顶部(我认为这是因为相对布局不知道将其放置在何处)。我还尝试将按钮栏设置在滚动视图的“下方”,但当滚动视图变得太大时,按钮栏就会消失。如前所述,您是否将android:layout\u marginTop=“200dip”替换为android:layout\u alignParentBottom=“true”是,将layout\u alignParentBottom=“true”替换为layout\u marginTop=“200dip”在按钮栏中,将该条从对话框顶部向下倾斜200度(而不是从滚动视图向下倾斜200度,这是我所需要的)。我没有在
线性布局中使用滚动视图
,而是使用嵌套滚动视图
,它允许使用布局权重
参数。