我在XML布局文件中放置了一个GridView。
它以我想要的方式在API17-21上显示(LTR),但是当我将语言转换为阿拉伯语(RTL)时,horizontalSpacing在API 17-19上被忽略,但是在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>项的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" />以下是我对阿拉伯语(RTL) UI的截图:
注意到第一个屏幕截图中的水平间距

发布于 2016-02-23 14:52:34
我也有同样的问题,我试着去解决它,但它并不像预期的那样起作用。如果您在清单中设置了RTL,那么将GridView的布局方向设置为LRT和rotateY 180。
发布于 2015-04-16 08:01:34
试试看,我不知道为什么,但为我工作
if(activity.getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)
gridView.setHorizontalSpacing((int) -padding);
else
gridView.setHorizontalSpacing((int) padding);发布于 2016-03-28 17:27:42
这个问题可以通过在包含GridView的布局中设置GridView来解决,然后,您需要创建两个布局,一个用于RTL,另一个用于LTR,并检查您应该使用的适配器类型。
https://stackoverflow.com/questions/27719638
复制相似问题