Android UiAutomatorViewer 无法检测到某些 View

标签 android navigation-drawer android-uiautomator

UiAutomatorViewer screenshot

我的应用在使用 UIAutomatorViewer 时遇到问题。如果您查看屏幕截图,突出显示的 View 应该是带有子 TextView 的 FrameLayout,但您没有看到。

该 Activity 具有以下 xml:

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.blahblah.MainActivity">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />



    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If you're not building against API 17 or higher, use
         android:layout_gravity="left" instead. -->
    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <fragment
        android:id="@+id/navigation_drawer"
        android:name="com.blahblah.NavigationDrawerFragment"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start" />

</android.support.v4.widget.DrawerLayout>

放置在这个 FrameLayout 中的 fragment 具有以下 xml:

<FrameLayout 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" tools:context="com.blahblah.BlankFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView android:layout_width="match_parent" android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />

</FrameLayout>

有人知道造成这种情况的潜在原因吗?

最佳答案

也许 id 丢失了?尝试为您的 TextView 元素设置 android:id。

关于Android UiAutomatorViewer 无法检测到某些 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26782517/

相关文章:

android - 使用抽屉导航检测键盘是否显示在 android 中

带有 RecyclerView 的 Android Drawer 在底部添加页脚

java - 多个 Activity 上的 Android 抽屉导航

android - 使用 UIAutomator 获取 android.widget.ListView 的所有子级

android-uiautomator - 如何使用 UIAutomator 在 Android 选项卡中滚动

android - ActionBar什么时候支持库

java - Android 滑动抽屉在创建时打开

android - 支持 Android SDK Level 16 的 uiautomator 版本是什么?

java - 使用 Lightweight-Stream-API 重写 java 8 方法以用于 api 21

java - Android SQLite数据库版本,更改结构现在无法查看DB