我有一个带有项目列表的回收者视图。这是它的外观:
我需要添加Talkback支持。问题在于聚焦在回收物品视图内的顺序。
这应该是正确的顺序:
1. Name of first member (A)
2. Amount under first member's name (2469...)
3. Name of second member (B)
4. Amount under second member's name (2469...)
问题是默认焦点顺序不同:
1) Name of the first member
2) Name of the second member
3) Amount under the first member
4) Amount under the second member
解决方案应该非常简单。有一个参数android:accessibilityTraversalBefore =“@ + id / someID”,它改变了焦点的顺序。我在我的应用程序的其他视图中使用此参数没有问题 - 它很好用。但是当我在这里使用它时根本没有任何效果 - 视图仍然以默认顺序聚焦。 我们来看看回收商项目布局:
<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:layout_width="match_parent"
android:layout_height="56dp">
<android.support.constraint.Guideline
android:id="@+id/vGuideline"
style="@style/Layout.Guideline"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"/>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/vFirstAvatar"
style="@style/Image.AvatarMember"
app:layout_constraintBottom_toBottomOf="parent"
tools:src="@drawable/avatar_multiple" />
<!-- Ellipsized because it can overlay the second member. -->
<android.support.v7.widget.AppCompatTextView
android:id="@+id/vFirstName"
style="@style/TextView.NameEllipsized"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="8dp"
android:importantForAccessibility="yes"
android:layout_marginRight="8dp"
android:accessibilityTraversalBefore="@+id/vFirstAmount"
android:textAppearance="@style/ListPrimaryTiny"
app:layout_constraintLeft_toRightOf="@+id/vFirstAvatar"
app:layout_constraintRight_toLeftOf="@+id/vGuideline"
app:layout_constraintTop_toTopOf="parent"
tools:text="Suzan" />
<!-- Ellipsized because it can overlay the second member. -->
<android.support.v7.widget.AppCompatTextView
android:id="@+id/vFirstAmount"
style="@style/TextView.NameEllipsized"
android:layout_marginTop="2dp"
android:accessibilityTraversalBefore="@+id/vSecondName"
android:textAppearance="@style/ListSecondary"
android:importantForAccessibility="yes"
app:layout_constraintLeft_toLeftOf="@+id/vFirstName"
app:layout_constraintRight_toRightOf="@id/vGuideline"
app:layout_constraintTop_toBottomOf="@+id/vFirstName"
tools:text="$22" />
<android.support.v7.widget.AppCompatImageView
android:id="@+id/vSecondAvatar"
style="@style/Image.Avatar"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/avatar_multiple" />
<!-- Ellipsized because it can overlay first member. -->
<android.support.v7.widget.AppCompatTextView
android:id="@+id/vSecondName"
style="@style/TextView.NameEllipsized"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:importantForAccessibility="yes"
android:accessibilityTraversalBefore="@+id/vSecondAmount"
android:layout_marginTop="11dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="end"
android:textAppearance="@style/ListPrimaryTiny"
app:layout_constraintLeft_toLeftOf="@+id/vGuideline"
app:layout_constraintRight_toLeftOf="@+id/vSecondAvatar"
app:layout_constraintTop_toTopOf="parent"
tools:text="Dave" />
<!-- Ellipsized because it can overlay the first member. -->
<android.support.v7.widget.AppCompatTextView
android:id="@+id/vSecondAmount"
style="@style/TextView.NameEllipsized"
android:layout_marginTop="2dp"
android:importantForAccessibility="yes"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="end"
android:textAppearance="@style/ListSecondary"
app:layout_constraintRight_toRightOf="@+id/vSecondName"
app:layout_constraintLeft_toLeftOf="@id/vGuideline"
app:layout_constraintTop_toBottomOf="@+id/vSecondName"
tools:text="$8" />
</android.support.constraint.ConstraintLayout>
您是否知道Talkback完全忽略的原因是什么? AccessibilityTraversalBefore属性?
答案 0 :(得分:0)
如果您查看&#34; TalkBack&#34;中的OrderedTraversalController。项目,你可以看到TalkBack确实尊重这个属性。我道歉,但我没有时间为此设置测试并确认,但我的猜测是,用XML设置它并不会起作用。回收器视图很可能在运行时覆盖XML属性。
在渲染完所有视图后尝试在代码中执行此操作。可能还涉及一些竞争条件!我实际上并不知道你必须使用什么回调才能让它可靠地发生。我稍后可能会进行调查。