如何设置导航抽屉被从右到左开 [英] How to set Navigation Drawer to be opened from right to left

查看:113
本文介绍了如何设置导航抽屉被从右到左开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我知道这个问题在这里出现过,但想了很多,我仍然没有成功之后。 我正在从示例 <一href="http://developer.android.com/training/implementing-navigation/nav-drawer.html#ActionBarIcon">Android开发者网站。

First of all I know this question appeared here before but after trying a lot i still didn't succeed. I working on the example from Android Developers site.

我试图将菜单设置为从右开到左其在本例中是如何实现(从左至右)代替。此外,我希望移动的开放式菜单按钮,右边的行动吧。我也红了一些答案,例如:<一href="http://stackoverflow.com/questions/17156340/android-is-navigation-drawer-from-right-hand-side-possible/17156831#17156831">in这个答案。

I'm trying to set the menu to be opened from right to left instead of how its implementing in the example (from left to right). In addition I want to move the open menu button to the right side of the action bar. I also red some answers here, for example in this answer.

我试图改变的意见和布局的重心,但是我得到的错误:

I try to change the gravity of the views and the layouts but I get the error:

没有与绝对重力LEFT发现抽屉里查看

您可以请帮我弄清楚什么是我的code和我应该以设置菜单中更改从右侧打开,移动操作栏按钮右侧的问题?

Can you please help me to figure out what is the problem in my code and what should I change in order to set the menu to be opened from the right, and to move the action bar button to the right side?

在XML code是在这里:

the xml code is here:

    <android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_gravity="right"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
    android:id="@+id/content_frame"
    android:layoutDirection="rtl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

<ListView android:id="@+id/left_drawer"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="10dp"
    android:background="#111"/>

    </android.support.v4.widget.DrawerLayout>

谢谢大家。

推荐答案

在主布局设置你的ListView重心向右:

In your main layout set your ListView gravity to right:

android:layout_gravity="right" 

另外,在您的code:

Also in your code :

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            if (item != null && item.getItemId() == android.R.id.home) {
                if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                    mDrawerLayout.closeDrawer(Gravity.RIGHT);
                } else {
                    mDrawerLayout.openDrawer(Gravity.RIGHT);
                }
            }
            return false;
        }
    };

希望工程:)

hope it works :)

这篇关于如何设置导航抽屉被从右到左开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆