【发布时间】:2019-09-25 14:25:08
【问题描述】:
我的应用中有一些屏幕上的 TalkBack 无法推断出正确的阅读顺序。根据文档,我可以使用android:accessibilityTraversalAfter和朋友来改变阅读顺序。但它不适用于我应该一起阅读的可聚焦ViewGroup 中的元素。
整个布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
android:accessibilityTraversalBefore="@id/before"
android:focusable="true"
tools:context=".MainActivity">
<TextView
android:id="@+id/before"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:accessibilityTraversalAfter="@id/before"
android:text="Before"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/after"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:accessibilityTraversalBefore="@id/after"
android:text="After"
app:layout_constraintBottom_toTopOf="@+id/before"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
它在屏幕中间渲染After,在底部渲染Before。我希望 TalkBack 将整个屏幕视为单个连续元素,因此我将 android:focusable 设置为 true。默认情况下,TalkBack 显示为:“之后,之前”。但我希望它阅读“之前,之后”。虽然我添加了android:accessibilityTraversalBefore 和android:accessibilityTraversalAfter,但它仍然显示为“After, before”。这是节点树调试的输出:
TreeDebug: (-2147455381)429.FrameLayout:(0, 0 - 1080, 1920):A
TreeDebug: (30189)429.TextView:(42, 101 - 397, 172):TEXT{My Application}:A:supportsTextLocation
TreeDebug: (31150)429.ViewGroup:(0, 210 - 1080, 1794):Fa:focusable:accessibilityFocused
TreeDebug: (33072)429.TextView:(499, 951 - 581, 1002):TEXT{After}:A:supportsTextLocation
TreeDebug: (32111)429.TextView:(485, 1743 - 595, 1794):TEXT{Before}:A:supportsTextLocation
我做错了什么?
为了完整性:minSdkVersion 是 26,targetSdkVersion 是 29。
【问题讨论】:
-
您能否验证一下,您是否在具有该布局的空白项目中看到了这种情况?还是您只能在您的应用/您的设置中重现该问题?
-
此布局是从使用空白模板使用 AS 3.5 创建的空示例应用程序中提取的。除了
onCreate()调用super()和setContentView()之外,活动为空。
标签: android android-layout android-view talkback android-accessibility