使用RTL语言的ListView布局不一致渲染(阿拉伯语)

Mik*_*nov 6 android listview right-to-left

我有简单的ListView与ArrayAdapter,它工作得很好.问题始于RTL语言(在本例中为阿拉伯语).

当你第一次打开它时,一切看起来都很好:

在此输入图像描述

但在向下滚动并向上滚动后,某些项目似乎呈现错误:

在此输入图像描述

代码很简单.请注意,如果我不重复查看,而是每次无条件地对其进行充气(请参阅下面的注释行),问题是GONE.但这显然是不对的,我想重新使用项目以获得更好的性能和流畅的滚动.

还请注意我ListView在应用程序中有多个s,并且所有这些都在阿拉伯语中显示这种不正确的呈现.对于这个问题,当我为每个列表项设置文本和图标时,我选择了最简单的情况.

请指教.我执行的代码部分ArrayAdapter:

    public class PagesListAdapter extends ArrayAdapter<IPageRef> {

        ...

        public View getView(int position, View convertView, @NonNull ViewGroup parent) {

            final IPageRef b = getItem(position);
            View row = convertView == null ? mInflater.inflate(R.layout.lang_item, parent, false) : convertView;
            //View row = mInflater.inflate(R.layout.wordlist_item, parent, false);

            TextView title = row.findViewById(R.id.title);
            ImageView img = row.findViewById(R.id.img);

            ... // (setting the title & img properties)

            return row;
        }
    }
Run Code Online (Sandbox Code Playgroud)

lang_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/img"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_width="50dp"
        android:layout_height="38dp"
        android:padding="1dp"
        />

    <TextView
        android:id="@+id/title"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:textSize="25sp" >
    </TextView>

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

Shm*_*uel -2

尝试对行项目使用相对布局,并将重力设置为“开始”和“结束”(而不是“左”和“右”),看看是否有帮助。

(如果您总是希望图像位于特定一侧,请使用左/右而不是开始/结束)

另外,请确保您的清单文件中有 rtl 支持 android:supportsRtl=true

https://developer.android.com/guide/topics/manifest/application-element.html