Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在导航抽屉菜单中对齐开关?_Android_Xml - Fatal编程技术网

Android 如何在导航抽屉菜单中对齐开关?

Android 如何在导航抽屉菜单中对齐开关?,android,xml,Android,Xml,这是我的导航抽屉布局 我不能校准这个开关 像这样 这是我的xml代码 toggle.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android

这是我的导航抽屉布局

我不能校准这个开关

像这样

这是我的xml代码

toggle.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<com.rey.material.widget.Switch
    style="@style/Material.Widget.Switch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:checked="false"/>
</RelativeLayout>

drawer.xml

<item android:title="Communicate">
    <menu>
        <item
            android:id="@+id/nav_share"
            android:icon="@drawable/ic_question"
            android:title="menual" />
        <item
            android:id="@+id/nav_send"
            android:icon="@drawable/ic_menu_send"
            android:title="Send" />
        <item
            android:id="@+id/it_sw"
            android:enabled="true"
            android:title="ON/OFF"
            android:visible="true"
            app:actionLayout="@layout/toggle"/>
    </menu>
</item>


出什么问题了?

试着将开关对准父对象的右侧

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.rey.material.widget.Switch
    style="@style/Material.Widget.Switch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:gravity="Right"
    android:checked="false"/>
</RelativeLayout>

我正在使用此代码,工作正常。我希望你能为你想做的事找到解决办法

菜单\u drawer.xml

<item
    android:id="@+id/mi_drawer_item_live_traffic"
    android:icon="@drawable/side_livetraffic"
    android:title="@string/drawer_item_live_traffic"
    app:actionLayout="@layout/layout_switch"
    />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.SwitchCompat
        android:id="@+id/drawer_switch"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:text=""/>
</LinearLayout>

layout\u switch.xml

<item
    android:id="@+id/mi_drawer_item_live_traffic"
    android:icon="@drawable/side_livetraffic"
    android:title="@string/drawer_item_live_traffic"
    app:actionLayout="@layout/layout_switch"
    />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.SwitchCompat
        android:id="@+id/drawer_switch"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:text=""/>
</LinearLayout>

试试android:gravity=“center | center”@你的开关