【问题标题】:View which is outside the bounds of relativelayout is not accessible无法访问相对布局范围之外的视图
【发布时间】:2021-05-17 04:20:25
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    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:id="@+id/parent"
    android:clipToPadding="false"
    android:clipChildren="false"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@color/black"
        android:clipChildren="false"
        android:clipToPadding="false">
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="100dp"
            android:text="Hello World " />
    </RelativeLayout>
</LinearLayout>

虽然使用上面的布局,其中按钮在外部是父相对布局边界,但按钮不可访问(对讲不会读出按钮详细信息)。 我们可以让这个按钮可以访问吗?

【问题讨论】:

    标签: android android-layout kotlin accessibility


    【解决方案1】:

    我使用我编写的AccessibilityService 来分析可通过您的布局提供给 AccessibilityServices 的“节点调试树”,并得到以下结果:

         androidx.core.view.accessibility.AccessibilityNodeInfoCompat@80007c5d;
            boundsInParent: Rect(0, 0 - 1080, 2340);
            boundsInScreen: Rect(0, 0 - 1080, 2340);
            packageName: com.testapp.testproject;
            className: android.widget.FrameLayout;
            text: null;
            contentDescription: null;
            viewId: null;
            checkable: false;
            checked: false;
            focusable: false;
            focused: false;
            selected: false;
            clickable: false;
            longClickable: false;
            enabled: true;
            password: false;
            scrollable: false;
            [ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_ACCESSIBILITY_FOCUS, ACTION_SHOW_ON_SCREEN]
    

    一开始我以为可能是无障碍服务,后来看了下LayoutInspector:

    而且看起来它永远不会被渲染。所以看起来你不能隐藏这样的按钮。

    我也会指给你WCAG guideline 3.2.7

    执行功能低下、记忆力受损以及其他认知和学习障碍的人如果隐藏起来,直到将焦点放在他们身上或指针悬停在他们身上,他们可能无法找到进步所需的控制。他们也可能不记得下次与网站交互时控件在哪里。

    某些设计方法会隐藏完成​​任务所需的控件,并需要某些用户交互(例如鼠标悬停)来显示这些控件。这些必需的交互可能会使有认知障碍的用户无路可走。

    所以总的来说,这似乎不是表面上的最佳实践

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-14
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多