我正在尝试Activity
在剩余空间中仅显示几个(或一个)首选项和更多小部件。我很难弄清楚如何做到这一点。
在/res/xml/preferences_1.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="test"
android:title="test"
android:defaultValue="false" />
</PreferenceScreen>
我想包含一个 ui 来编辑这个单一首选项的活动的布局: /res/layout/test.xml:
<?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="fill_parent"
android:layout_height="fill_parent">
<fragment
android:name="com.test.something.TestActivity$PrefsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View ... stuff ... />
</LinearLayout>
和Activity
:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public static class PrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from XML resource
this.addPreferencesFromResource(R.xml.preference_login);
};
}
}
这应该说明我想要实现的目标:让<fragment>
显示PreferenceFragment
和下方仍然有一个(或一些)小部件。
可悲的是,这并没有像我希望的那样工作。相反,它在打开活动时抛出。堆栈跟踪的相关部分似乎是:
E/AndroidRuntime(12584): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.something/com.test.something.TestActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class分段
有人可以告诉我这是怎么做到的吗?