ConstraintLayout ListView RTL有些行不是RTL

时间:2018-06-27 13:30:45

标签: android android-layout right-to-left android-constraintlayout

在我的 ListView 上,某些行未 RTL对齐滚动并重新绘制线条后,即可。

我的订单项布局:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/clFrontView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp">

    <ImageView
        android:id="@+id/ivCircle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/circle"
        tools:ignore="ContentDescription"
        android:layout_marginTop="5dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

    <ImageView
        android:id="@+id/ivReminderType"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        tools:ignore="ContentDescription"
        app:layout_constraintTop_toTopOf="@id/ivCircle"
        app:layout_constraintBottom_toBottomOf="@id/ivCircle"
        app:layout_constraintStart_toStartOf="@id/ivCircle"
        app:layout_constraintEnd_toEndOf="@id/ivCircle"
        app:layout_constraintLeft_toLeftOf="@id/ivCircle"
        app:layout_constraintRight_toRightOf="@id/ivCircle" />

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/civContactImage"
        android:layout_width="42dp"
        android:layout_height="42dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

    <ImageView
        android:id="@+id/icivCircleSmall"
        android:layout_width="15dp"
        android:layout_height="15dp"
        app:layout_constraintEnd_toEndOf="@id/civContactImage"
        app:layout_constraintRight_toRightOf="@id/civContactImage"
        app:layout_constraintBottom_toBottomOf="@id/civContactImage"
        tools:ignore="ContentDescription"/>

    <TextView
        android:id="@+id/tvTextLine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        tools:text="Line of Text"
        android:textSize="18sp"
        android:maxLines="2"
        app:layout_constraintLeft_toRightOf="@id/ivCircle"
        app:layout_constraintStart_toEndOf="@id/ivCircle"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"/>

    <TextView
        android:id="@+id/tvTextLine2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:textSize="16sp"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="@id/tvTextLine"
        app:layout_constraintLeft_toLeftOf="@id/tvTextLine"
        app:layout_constraintTop_toBottomOf="@id/tvTextLine" />

    <TextView
        android:id="@+id/tvTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        tools:text="Wed, 01.05.2018 10:10"
        android:textColor="#FF909090"
        android:textSize="12sp"
        android:drawablePadding="5dp"
        app:layout_constraintStart_toStartOf="@id/tvTextLine"
        app:layout_constraintLeft_toLeftOf="@id/tvTextLine"
        app:layout_constraintTop_toBottomOf="@id/tvTextLine2" />

    <TextView
        android:id="@+id/tvRepeat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        tools:text="Every 2nd Friday"
        android:textColor="#FF909090"
        android:textSize="12sp"
        android:drawablePadding="5dp"
        app:layout_constraintStart_toStartOf="@id/tvTextLine"
        app:layout_constraintLeft_toLeftOf="@id/tvTextLine"
        app:layout_constraintTop_toBottomOf="@id/tvTime" />

</android.support.constraint.ConstraintLayout>

首先启动看起来像这样,第一行不是RTL:
enter image description here

向下滚动并向上滚动到顶部之后,它是正确的:
enter image description here

build.gradle依赖项:

implementation 'com.android.support.constraint:constraint-layout:1.1.2'

2 个答案:

答案 0 :(得分:0)

这些更改可能有效:

<ImageView
    android:id="@+id/ivCircle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/bg_circle_win"
    app:layout_constraintBottom_toBottomOf="@+id/civContactImage"
    app:layout_constraintStart_toStartOf="@+id/civContactImage"
    tools:ignore="ContentDescription" />

<ImageView
    android:id="@+id/ivReminderType"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    app:layout_constraintEnd_toEndOf="@+id/civContactImage"
    app:layout_constraintTop_toTopOf="@+id/civContactImage"
    tools:ignore="ContentDescription" />

<de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/civContactImage"
    android:layout_width="42dp"
    android:layout_height="42dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/icivCircleSmall"
    android:layout_width="15dp"
    android:layout_height="15dp"
    app:layout_constraintEnd_toEndOf="@id/civContactImage"
    app:layout_constraintRight_toRightOf="@id/civContactImage"
    app:layout_constraintBottom_toBottomOf="@id/civContactImage"
    tools:ignore="ContentDescription"/>

<TextView
    android:id="@+id/tvTextLine"
    android:layout_width="wrap_content"
    android:layout_height="23dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:gravity="center_vertical"
    android:maxLines="2"
    android:textSize="18sp"
    app:layout_constraintEnd_toStartOf="@+id/civContactImage"
    tools:text="Line of Text" />

<TextView
    android:id="@+id/tvTextLine2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:textSize="16sp"
    android:visibility="gone" />

<TextView
    android:id="@+id/tvTime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:drawablePadding="5dp"
    android:gravity="center_vertical"
    android:textColor="#FF909090"
    android:textSize="12sp"
    app:layout_constraintEnd_toStartOf="@+id/civContactImage"
    app:layout_constraintTop_toBottomOf="@+id/tvTextLine"
    tools:text="Wed, 01.05.2018 10:10" />

<TextView
    android:id="@+id/tvRepeat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:drawablePadding="5dp"
    android:gravity="center_vertical"
    android:textColor="#FF909090"
    android:textSize="12sp"
    app:layout_constraintEnd_toStartOf="@+id/civContactImage"
    app:layout_constraintTop_toBottomOf="@+id/tvTime"
    tools:text="Every 2nd Friday" />

我希望工作。祝你好运

答案 1 :(得分:0)

尝试这个也许可以解决问题。有一些小的测试更改,您可以根据需要将其删除,首先,我将tools:text更改为android:text,以便显示虚拟数据。其次,两个图像视图分别命名为 ivReminderType icivCircleSmall 我已经放置了两个默认图像只是出于测试目的,因此请进行更改。还有一个名为 icivCircleSmall 的imageview,我不知道应该将其链接到哪里,因此我没有编辑为此编写的任何代码。下面是xml的编辑代码。

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/clFrontView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="10dp">

    <ImageView
        android:id="@+id/ivCircle"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toTopOf="@+id/tvRepeat"
        app:layout_constraintEnd_toStartOf="@+id/tvTime"
        app:layout_constraintTop_toBottomOf="@+id/tvTextLine"
        tools:ignore="ContentDescription" />

    <ImageView
        android:id="@+id/ivReminderType"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="@+id/tvRepeat"
        app:layout_constraintEnd_toStartOf="@+id/tvRepeat"
        app:layout_constraintTop_toBottomOf="@+id/tvTime"
        tools:ignore="ContentDescription" />

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/civContactImage"
        android:layout_width="42dp"
        android:layout_height="42dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/icivCircleSmall"
        android:layout_width="15dp"
        android:layout_height="15dp"
        app:layout_constraintBottom_toBottomOf="@id/civContactImage"
        app:layout_constraintEnd_toEndOf="@id/civContactImage"
        app:layout_constraintRight_toRightOf="@id/civContactImage"
        tools:ignore="ContentDescription" />

    <TextView
        android:id="@+id/tvTextLine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:gravity="center_vertical"
        android:maxLines="2"
        android:text="Line of Text"
        android:textSize="18sp"
        app:layout_constraintEnd_toStartOf="@+id/civContactImage"
        app:layout_constraintTop_toTopOf="@+id/civContactImage" />

    <TextView
        android:id="@+id/tvTextLine2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:textSize="16sp"
        android:visibility="gone"
        app:layout_constraintLeft_toLeftOf="@id/tvTextLine"
        app:layout_constraintStart_toStartOf="@id/tvTextLine"
        app:layout_constraintTop_toBottomOf="@id/tvTextLine" />

    <TextView
        android:id="@+id/tvTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:drawablePadding="5dp"
        android:gravity="center_vertical"
        android:text="Wed, 01.05.2018 10:10"
        android:textColor="#FF909090"
        android:textSize="12sp"
        app:layout_constraintEnd_toStartOf="@+id/civContactImage"
        app:layout_constraintTop_toBottomOf="@id/tvTextLine2" />

    <TextView
        android:id="@+id/tvRepeat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawablePadding="5dp"
        android:gravity="center_vertical"
        android:text="Every 2nd Friday"
        android:textColor="#FF909090"
        android:textSize="12sp"
        app:layout_constraintEnd_toEndOf="@+id/tvTime"
        app:layout_constraintLeft_toLeftOf="@id/tvTextLine"
        app:layout_constraintStart_toStartOf="@id/tvTextLine"
        app:layout_constraintTop_toBottomOf="@id/tvTime" />

</android.support.constraint.ConstraintLayout>

希望有帮助!