导航抽屉,从右侧开始 [英] Navigation drawer starts from right side

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

问题描述

我怎样才能使导航抽屉从左侧向右打开?

How can i make the navigation drawer open from the right to the left?

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

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">

navigation.xml

navigation.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>

这是我如何主要活动创建

This is how i create it in main activity

navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
              (..........)

我如何能做到吗?我试过的android:引力,但它不能正常工作

How can i make it ? I've tried android:gravity but it doesn't work.

推荐答案

在你的的main.xml 还有就是 android.support.design。 widget.NavigationView 具有以下属性:的android:layout_gravity =结束。你必须将其设置为右键的,所以这将是这样的:的android:layout_gravity =正确的
其余的是由设计支持LIB完成。

In your main.xml there is the android.support.design.widget.NavigationView which has the following attribute: android:layout_gravity="end". You have to set it to right, so it will be like this: android:layout_gravity="right". The rest is done by the design support lib.

请注意,在Android Studio会显示你应该使用结束而不是右键警告为了确保在从右到左的语言正确的行为。您可以忽略此消息。

Note that the Android Studio will show a warning that you should use end instead of right in order to ensure correct behavior in right-to-left languages. You can ignore this message.

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

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