水平间距中的GridView错误

mal*_*yeb 7 android gridview android-layout

我在我的XML布局文件中放置了一个GridView.

它在API 17-21上以英语(LTR)显示,但是当我将语言转换成阿拉伯语(RTL)时,在API 17-19中忽略horizo​​ntalSpacing,但在API 21上它会按我的意愿显示.

仿真器和真正的Android设备上也出现了相同的行为.

XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/services_home_main_layout"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/services_home_contents"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/services_home_bottom_layout">

        <GridView
            android:id="@+id/services_home_services_gridview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="3"
            android:horizontalSpacing="4dp"
            android:verticalSpacing="4dp"
            android:layout_margin="4dp"
            android:gravity="center"
            android:choiceMode="singleChoice" />

    </LinearLayout>

    <LinearLayout
        android:id="@id/services_home_bottom_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

项目的XML代码:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/services_drawer_item_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="center"
    android:padding="4dp"
    android:background="@color/Gray_CC"
    android:drawableTop="@drawable/tall4"
    android:text="@string/app_name" />
Run Code Online (Sandbox Code Playgroud)

这是我的阿拉伯语(RTL)UI截图:

注意第一个屏幕截图中的水平间距

在此输入图像描述

box*_*box 3

我遇到了同样的问题,我尝试解决它,但它只是没有按预期工作。如果您在清单中设置了 RTL,则将 GridView 的布局方向设置为 LRT 并将 Y 旋转 180 度。

这里有详细的解释:android grid view place items from right to left