2

LTR と RTL の両方をサポートするアプリが必要です。サポート ライブラリを使用して NavigationView を使用しています。このナビゲーション ビューのメニューには、2 つの項目を含めました。そのうちの 1 つは単なるアイコンとテキストで、もう 1 つはスイッチです。RTL モードのスイッチを除いて、すべてが期待どおりに機能します。

LTR モードでのナビゲーション ビューは次のようになります。

ここに画像の説明を入力

デバイスの言語が RTL に設定されている場合は、次のようになります。

ここに画像の説明を入力

RTL モードでのスイッチの問題は次のとおりです。

1- 画像のアイコンが表示されない

2- アイテムのテキストが表示されない

3- スイッチはナビゲーション ビューの中央ではなく左側にあるはずです

どうすれば修正できますか?

ナビゲーション ビューのメニューの XML は次のとおりです。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_view_menu">
    <group>
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_home_white_24dp"
            android:title="Home" />
        <item
            android:id="@+id/image_switch_parent"
            android:icon="@drawable/ic_photo_library_white_24dp"
            android:title="@string/images"
            app:actionLayout="@layout/nav_view_switch"
            app:showAsAction="always" />
    </group>
</menu>

スイッチの実際のレイアウトは次のとおりです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.SwitchCompat
        android:id="@+id/image_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />
</RelativeLayout>
4

1 に答える 1

0

RelativeLayoutに変更してLinearLayout10 dp の上余白を追加することで、最終的に修正しましたSwitchCompat。したがって、今のコードはSwitchCompat次のようになります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.SwitchCompat
        android:id="@+id/nav_image_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />
</LinearLayout>
于 2016-01-24T08:03:34.557 に答える