我正在开发一个有多个 recyclerView 的应用程序。当我使用对讲在项目之间滑动时,它不会指定项目大小之外的项目位置,例如 1 / 12。
但是我创建了一个示例应用程序,它说项目位置超出项目大小。所以我想知道可能是什么原因导致talkback没有指定RecyclerView中的位置和大小。
这是我的有效示例:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="16dp"
android:gravity="center"
android:text="Hello"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
这是列表项适配器:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.cardview.widget.CardView
android:layout_width="125dp"
android:layout_height="wrap_content"
android:focusable="true"
android:layout_margin="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/id_tag"
android:textColor="@color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp" />
<TextView
android:id="@+id/name"
android:textColor="@color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</layout>
您是否知道为什么对讲不能说出位置和物品尺寸?
在 RecyclerView 版本 1.2.0-alpha02(2020 年 4 月 1 日)及更新版本中,如果您希望辅助服务(例如 Talkback)继续向用户指示计数和项目索引,您将需要自己填充 CollectionInfo 和 CollectionItemInfo .