嵌套的PreferenceScreens会丢失自定义PreferenceActivity布局

时间:2011-01-27 21:16:37

标签: android preferences preferencescreen

我有一个首选项活动,它从以下XML获取它的布局。这会使按钮显示在首选项的底部。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/com.stealthcopter.nexus.nexusgl"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<ListView android:id="@android:id/list"
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
<Button android:text="This is a button on top of all preferences."
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />         
</LinearLayout>

然而,当打开其中的嵌套PreferenceScreen时,它会恢复为仅显示列表视图,是否有一种简单的方法可以在首选项屏幕之间保持相同的布局?

我尝试过PreferenceScreen.setLayoutResource(R.id.layout.main);但这只会改变打开前显示的视图

更新

通过将嵌套的PreferenceScreens更改为普通首选项并覆盖其onclick方法以清除listview中的首选项并从适当的XML文件重新加载首选项来修复(Kludged)这个。

2 个答案:

答案 0 :(得分:1)

我认为这是所述错误的另一个症状here 解决方法是每次打开首选项屏幕时重置布局。

答案 1 :(得分:0)

您希望使用自定义首选项屏幕实现什么目标?这里没有优先考虑?我也非常确定首选项布局必须在'xml'文件夹中,而不是'layout'