ListView的第一个条目对于RTL总是不正确 [英] ListView's first entry always incorrect for RTL

查看:82
本文介绍了ListView的第一个条目对于RTL总是不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,当我使用RTL时,ListView中的第一个条目总是被错误地翻转.例如:

For some reason, the first entry in my ListView is always flipped the wrong way around when I use RTL. For example:

附加信息:

  1. ListView在DialogFragment中.

  1. The ListView is in a DialogFragment.

我已经更新了清单以支持RTL(应用程序的其余部分工作正常)

I HAVE updated my manifest to support RTL (the rest of the app works fine)

ListView有一个适配器,每个项目的布局如下:

The ListView has an Adapter, the layout per item looks like:

<ImageView
    android:id="@+id/dropdown_icon"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:src="@drawable/photo_button_disabled"
    android:layout_gravity="center_horizontal"/>

<ImageView
    android:id="@+id/count_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:scaleType="fitCenter"
    android:layout_alignEnd="@+id/dropdown_icon"
    android:layout_alignRight="@+id/dropdown_icon"
    android:layout_alignStart="@+id/dropdown_icon"
    android:layout_alignLeft="@+id/dropdown_icon"
    android:layout_alignTop="@+id/dropdown_icon"
    android:layout_alignBottom="@+id/dropdown_icon"
    android:adjustViewBounds="true"/>

对话框片段的布局如下:

While the layout for the Dialog Fragment looks like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:background="@drawable/rounded_bg">

<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:textSize="@dimen/dialog_title"
    android:padding="10dp"/>

<LinearLayout
    android:layout_below="@+id/title"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!-- This table should be populated with all the different options -->
        <ListView
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/entry_list"
            android:divider="?android:attr/dividerHorizontal"
            android:showDividers="middle"
            android:background="@color/overlay"
            android:descendantFocusability="afterDescendants"
            android:animateLayoutChanges="true">
        </ListView>


    <!-- The save and clear buttons-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/general_padding"
        android:paddingTop="@dimen/general_padding"
        android:paddingRight="@dimen/general_padding">

        <TextView
            android:id="@+id/warning_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="@string/recon_value_required"
            android:visibility="gone"
            android:textColor="@color/warningColour"
            android:layout_marginBottom="@dimen/list_vertical_margin"/>

        <LinearLayout
            android:id="@+id/button_container"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:layout_below="@id/warning_label"
            android:paddingBottom="@dimen/general_padding">
            <Button
                android:id="@+id/clear_button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_button"
                android:text="@string/clear"
                android:textColor="@color/buttonTextColour"
                android:layout_weight="1"
                android:foreground="?attr/selectableItemBackground"
                android:layout_marginRight="8dp"
                android:layout_marginEnd="8dp"/>

            <Button
                android:id="@+id/save_button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_button"
                android:text="@string/save"
                android:textColor="@color/buttonTextColour"
                android:layout_weight="1"
                android:foreground="?attr/selectableItemBackground"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"/>
        </LinearLayout>

    </RelativeLayout>

</LinearLayout>
</RelativeLayout>

我不确定还有什么可以尝试的.我摆弄了不同的布局.更改方向不能解决问题.任何帮助将不胜感激.

I'm not sure what else to try. I have fiddled with the different layouts. Changing orientation doesn't fix the issue. Any help would be greatly appreciated.

推荐答案

在探索时,我发现问题仅发生在Dialogs中的ListViews上(我尝试过AlertDialog),并且最高的ListView行的方向性在之后已修复.向下滚动并向上备份.我不确定为什么会发生这种情况,只能提出建议

On exploring, I've found that the problem only happens on ListViews in Dialogs (I tried AlertDialog), and the directionality of the topmost ListView row is fixed after scrolling down and back up. I'm not sure why it happens, and can only suggest

  1. 通过添加 rowView.setLayoutDirection(getContext().getResources().getConfiguration().getLayoutDirection())来手动设置基于配置的方向(基于设备语言已相当可靠地更新); 在ListAdapter的 getView
  2. 不要重复使用/回收您的 ListView 行/项目,尽管这可能会降低您的应用速度并且可能是不可取的
  3. 切换到RecyclerView
  1. manually setting the direction based on configuration (that is quite reliably updated based on device language) by adding rowView.setLayoutDirection(getContext().getResources().getConfiguration().getLayoutDirection()); in the getView of your ListAdapter
  2. Not reusing/recycling your ListView rows/items, though this might slow down your app and is probably unadvisable
  3. Switching to RecyclerView

P.S.请参阅与此问题相同的此问题

P.S. See this question with the same issue

P.P.S.getView似乎被大量调用,并且不定期地仅用于Dialogs中的ListViews,而不是Fragments/Activities中的ListViews,并且可能值得研究.尽管不能保证ListView的行为,但仍然有些奇怪

P.P.S. getView seems to be called a lot and irregularly only for ListViews in Dialogs and not those in Fragments/Activities, and might be worth looking into. Although ListView behaviour is not guaranteed, it's still a little strange

这篇关于ListView的第一个条目对于RTL总是不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆