问题描述
- 新手提问DrawerLayout
-
Drawerlayout与Viewpager+Fragment冲突,,drawerlayout无法正常关闭,,可以划开,但是不能关闭,,如何添加代码(使用了开源的PagerSlidingTabStrip)``` protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
//设置Drawerlayourt的打开关闭
toolbar.setTitle("");
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,R.string.drawer_open, R.string.drawer_close);
toggle.syncState();
drawerLayout.setDrawerListener(toggle);
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
tabs.setViewPager(viewPager);
menuadapter=new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,aaa);
leftMenu.setAdapter(menuadapter);
}<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#0099FF" > <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:text="人在民大" android:textSize="20dp" android:textColor="#000" /> </android.support.v7.widget.Toolbar> <android.support.v4.widget.DrawerLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/drawerlayout" android:layout_below="@id/toolbar" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:background="#fff" android:orientation="vertical"> <ListView android:id="@+id/leftMenu" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.astuetz.PagerSlidingTabStrip android:id="@+id/tabs" style="@style/pagerTabStype" android:layout_width="match_parent" android:layout_height="48dip" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </android.support.v4.widget.DrawerLayout> </LinearLayout>
解决方案
这两个肯定会冲突的,你把viewpager的滑动关掉试试呢。不然就只能通过点击开启DrawerLayout了..
解决方案二:
解决冲突:http://blog.csdn.net/a1681681238/article/details/50435115