【发布时间】:2015-08-22 10:36:55
【问题描述】:
如何让导航抽屉从右向左打开?
Main.xml
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/navigation"
android:background="#FFE7FF"/>
drawer_header.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:baselineAligned="false"
android:orientation="vertical">
导航.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/Home"
android:checked="true"
android:icon="@drawable/homelogo"
android:title="Home" /></group></menu>
这就是我在主要活动中创建它的方式
navigationView = (NavigationView) findViewById(R.id.navigation_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
(..........)
我该怎么做?我试过 android:gravity 但它不起作用。
【问题讨论】:
-
btnHome.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO 自动生成的方法存根 hideKeyboard(); handleDrawerLayout(); } });
-
这是重复的问题,请参考:stackoverflow.com/questions/17852091/…
-
我试过了,但我正在使用导航视图打开抽屉,drawerLayout.openDrawer(navigationView); ,所以我不能在这条线内使用重力