我正在努力使现有的 Android 应用程序易于访问,但发现它非常令人沮丧,许多应该工作的东西却没有。
我正在尝试将描述的内容组合在一起,就像在Google Codelabs 示例中描述的那样,但它仍然使部分内容可用于手势导航:
我有一个Fragment具有LinearLayout垂直方向的 a 作为根视图 3 RelativeLayouts,每个都包含一个ImageView和 a TextView。
就像在代码实验室中一样,我已将 设置RelativeLayout为可聚焦,因为ImageViews我已将 设置ContentDescription为 null,因为它们纯粹是装饰性的。
这是其中一个与 root的XML布局:RelativeLayoutsLinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
tools:context="com.my.fancyapp.fragments.OtherFragment">
<RelativeLayout
android:id="@+id/item_youtube"
android:layout_width="match_parent"
android:layout_height="@dimen/other_item_height"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/other_item_padding">
<ImageView
android:id="@+id/ivYouTube"
android:layout_width="@dimen/other_icon_width"
android:contentDescription="@null"
android:layout_height="match_parent"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/other_text_margin_left"
android:text="YouTube"
android:textAppearance="@style/ArtistTextAppearance" />
</RelativeLayout>
...
</LinearLayout>
在 中Fragment,我onClickListener为 each设置了一个RelativeLayout,它链接到透视图(Youtube 频道、Facebook 页面或带有 impressum 的 Webview)并ImageView加载Picasso:
itemYoutube.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(youTubeUrl));
startActivity(intent);
}
}
});
Picasso.with(getActivity())
.load(R.drawable.icon_youtube)
.fit()
.centerInside()
.into(iconYoutube);
itemYoutube.setContentDescription(getString(R.string.youtube));
现在的问题是,尝试单击一个项目,然后通过滑动到下一个项目进行导航会导致文本被突出显示,而不是通过导航到下一个RelativeLayout
有谁知道,为什么焦点跳到下一个TextView而不是下一个RelativeLayout?
我尝试了以下方法:
RelativeLayouts为in XML设置 ContentDescription- 将 ContentDescription 设置为
TextViewsnull(可能不好) - 更改了设置内容描述的顺序
- 设置
TextViews为可聚焦:false - 删除了 的 ContentDescription
RelativeLayouts,这导致导航到TextViews唯一而不是RelativeLayout按希望突出显示整体
与 Codelabs 示例相反,我在ImageView里面有一个问题,RelativeLayout而只有TextViews那些应该全部读出,这可能是一个问题吗?ClickListener或者在通过 xml 设置某些值以及通过代码动态设置其他值时是否存在问题?我完全一无所知。

