2

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

这是我的 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 cannot be cast to android.view.ViewGroup in main_menu.xml

我想做这样的事情:图片示例

4

0 回答 0