2

如何更改项目方向菜单?

我需要将图标方向更改为 RTL 而不是 LTR,我使用GravityLayout_Gravity不工作。

我能做些什么 ?下面是我的 XML :

在此处输入图像描述

menu_start.xml :

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/circle"
            android:title="@string/Search" />
        <item
            android:id="@+id/nav_example_item_1"
            android:icon="@drawable/circle"
            android:title="Example Item #1" />
    </group>

    <item android:title="Sub items">
        <menu>
            <item
                android:id="@+id/nav_example_sub_item_1"
                android:title="Example Sub Item #1" />
        </menu>
    </item>

</menu>

活动开始.xml:

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/KeepToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!-- We use a Toolbar so that our drawer can be displayed
                 in front of the action bar -->
            <android.support.v7.widget.Toolbar
                android:id="@+id/my_awesome_toolbar_Start"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/ORANGE_700">

                <ImageView
                    android:id="@+id/drawer_indicator"
                    android:layout_width="30dp"
                    android:layout_height="30dp" />
            </android.support.v7.widget.Toolbar>

            <!-- The rest of your content view -->

        </LinearLayout>


        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/KeepToolbar"
            android:orientation="vertical">

            <ViewFlipper
                android:id="@+id/viewflipper"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:autoStart="true"
                android:background="@color/ORANGE_700"
                android:inAnimation="@anim/right_in"
                android:outAnimation="@anim/left_out">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/a" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/b" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/c" />
            </ViewFlipper>

            <android.support.v7.widget.RecyclerView

                android:id="@+id/cardList"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:dividerHeight="1dp"
                android:scrollbarDefaultDelayBeforeFade="5000"
                android:scrollbarFadeDuration="5000"
                android:scrollbars="vertical" />
        </LinearLayout>
    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@drawable/background_color"
        app:headerLayout="@layout/header_drawer"
        app:menu="@menu/menu_start" />

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

1 回答 1

3

试试这个:首先添加{ android:supportsRtl="true" }AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:supportsRtl="true" >

</application>

然后在您activity_start.xml将这两行添加到 DrawerLayout :

android:layoutDirection="rtl"
android:textDirection="anyRtl"
于 2015-09-28T18:00:41.300 回答