带滑动菜单的偏好活动

时间:2013-04-06 22:22:21

标签: android preferenceactivity slidingmenu

我正在尝试将偏好活动放在滑动菜单的后面内容中。

这是我的main_menu.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#202222"
tools:context=".MainActivity" >

<PreferenceScreen
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

<PreferenceCategory android:title="@string/general" >
    <Preference android:title="@string/news" />
    <Preference android:title="@string/sport" />
    <Preference android:title="@string/business" />
    <Preference android:title="@string/economy" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/news" >
    <Preference android:title="@string/international" />
    <Preference android:title="@string/national"/>
    <Preference android:title="@string/local" />
</PreferenceCategory>

</PreferenceScreen>

这是我在MainActivity.java中所做的事情

public class MainActivity extends SlidingActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setBehindContentView(R.layout.main_menu);

    getSlidingMenu().setBehindOffset(120);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

当我运行应用程序时,它崩溃并说“无法充气.android.view.InflateException:二进制XML文件行#12:错误导致类PreferenceScreen

我也有这个例外:com.android.layoutlib.bridge.MockView无法强制转换为main_menu.xml中的android.view.ViewGroup

我想做那样的事情:image example

0 个答案:

没有答案
相关问题