Tôi đã đặt GridView trong tệp bố cục XML của mình.Lỗi GridView ở khoảng cách ngang
Nó được hiển thị như tôi muốn bằng tiếng Anh (LTR) trên cả hai API 17-21 Nhưng khi tôi phù hợp ngôn ngữ với tiếng Ả Rập (RTL) thì HorizontalSpacing bị bỏ qua trên API 17-19 nhưng trên API 21 nó được hiển thị như tôi muốn.
Hành vi tương tự đã xảy ra trên trình mô phỏng và thiết bị Android thực.
mã 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>
mã XML cho các hạng mục:
<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" />
Dưới đây là ảnh chụp màn hình của tôi về tiếng Ả Rập (RTL) UI:
Chú ý khoảng cách ngang trong ảnh chụp màn hình đầu tiên
Điều này sẽ làm việc cho GridView với hình ảnh chỉ nhưng nếu có văn bản quá nó có thể được nhân đôi. Vì vậy, mục Lưới cũng cần phải được xoay 180. – darshanz
Tôi chỉ cần đặt hướng đến 'grid.setLayoutDirection (View.LAYOUT_DIRECTION_LTR)' và nó hoạt động. –