我试图将SlidingMenu与ViewPager一起使用,但无法使其工作。我遵循了jfeinstein描述的简单例子。当我从SlidingMenu中的onCreate方法中删除MainActivity时,活动就会启动并正确地显示viewpager,所以viewpager没有什么问题。如何将布局文件设置正确?许多类似的问题,但没有一个对我有用。是否需要在查看器内的片段中指定某些内容?
MainActivity:
public class MainActivity extends SherlockFragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.menu);
}
.....
}activity_main.xml
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />menu.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.jeremyfeinstein.slidingmenu.example.SampleListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</fragment>这就是我所犯的错误
E/AndroidRuntime(1780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.exampleapp/com.example.exampleapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment发布于 2013-10-24 10:37:39
不能将包含片段的XML膨胀到片段中。
检查here。
https://stackoverflow.com/questions/19563455
复制相似问题