【问题标题】:SwitchCompat is not shown properly on RTL modeSwitchCompat 在 RTL 模式下未正确显示
【发布时间】:2016-01-24 16:03:34
【问题描述】:

我需要我的应用同时支持 LTR 和 RTL。我正在使用使用支持库的 NavigationView。在这个导航视图的菜单中,我包括了两个项目。其中一个只是一个图标和一个文本,另一个是开关。一切都按预期工作,不包括处于 RTL 模式的 Switch。

以下是 LTR 模式下导航视图的外观:

当设备的语言设置为 RTL 语言时,情况相同:

这些是 Switch 在 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>

【问题讨论】:

    标签: android android-support-library switchcompat


    【解决方案1】:

    我最终通过将RelativeLayout 更改为LinearLayout 并为SwitchCompat 添加了10dp 的上边距来修复它。所以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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      相关资源
      最近更新 更多