我正在使用Preferences-API
来创建我的设置屏幕。
截至目前,我的SettingsActivity
布局XML包含一个简单的LinearLayout
,里面有一个FrameLayout
,我用它来包含我的Preferences
片段。
但是,由于用户访问设置屏幕的方式,AppBar中没有“后退”按钮 - 因此,我想在“首选项”屏幕的底部显示一个ButtonBar
,这样他们就可以点击一个cancel
或者ok
按钮..
这是我到目前为止尝试添加ButtonBar的内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SettingsActivity">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button style="?android:attr/buttonBarButtonStyle"
android:id="@+id/btn_settingsActivity_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/cancel" />
<Button style="?android:attr/buttonBarButtonStyle"
android:id="@+id/btn_settingsActivity_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok" />
</LinearLayout>
</LinearLayout>
有谁知道我做错了什么?
使用上面的代码,FrameLayout
仍然占据整个屏幕。
如果我给FrameLayout
一个特定的height
,我可以看到ButtonBar
。
但是,我知道这不是我应该怎么做的。
有人可以帮忙解释我应该怎么做这个吗?
谢谢!
首先在您的孩子LinearLayout中添加一些方向,例如qazxsw poi并将高度改为qazxsw poi。
android:orientation="horizontal"
第二个告诉你的wrap_content
你想通过重量属性占据剩余的空间,例如<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">..
和性能目的将高度设置为零FrameLayout
。
android:layout_weight="1"
最终代码应如下所示:
android:layout_height="0dp"