Android Espresso 点击 ImageButton 的位置错误
Android Espresso click on ImageButton clicks on wrong position
当我尝试点击图像按钮时,UI 在 android 上的浓缩咖啡测试出现问题:
我有以下布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF">
<ImageButton
android:id="@+id/parent_task_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:rotation="90"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_subdirectory_arrow_left_black_24dp"
android:paddingRight="10dp"
android:paddingLeft="12dp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/layout_divider"></View>
<com.mypackage.ui.TasklistItem
android:id="@+id/parent_task_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在我的应用程序中,它看起来像这样:
在我的浓缩咖啡测试中,我尝试点击其中的按钮(带箭头的那个):
onView(withId(R.id.parent_task_button)).perform(click());
但是点击没有按预期工作。我逐步完成了它(启用 android "Show Taps" 和 "Pointer location" 开发人员设置),结果是测试没有点击以图像按钮为中心,而是点击这里:
...正好在分隔线上,但不在 ImageButton 的中心。
如果我将 ImageButton 替换为普通 Button,则点击正确并且测试有效!
有谁知道这里的问题是什么或如何解决?
我找到了导致问题的行(在 ImageButton 中):
android:rotation="90"
如果我从图像按钮中删除这个旋转,则点击正确地在中间。
所以我的临时解决方法是旋转可绘制对象本身而不是按钮。
我目前也在研究 android espresso 代码并试图找出这里有问题的代码。
似乎点击坐标的计算是错误的,因为它忽略了旋转,因此计算错误。
如果我发现什么,会更新这个 post。
当我尝试点击图像按钮时,UI 在 android 上的浓缩咖啡测试出现问题:
我有以下布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF">
<ImageButton
android:id="@+id/parent_task_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:rotation="90"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_subdirectory_arrow_left_black_24dp"
android:paddingRight="10dp"
android:paddingLeft="12dp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/layout_divider"></View>
<com.mypackage.ui.TasklistItem
android:id="@+id/parent_task_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在我的应用程序中,它看起来像这样:
在我的浓缩咖啡测试中,我尝试点击其中的按钮(带箭头的那个):
onView(withId(R.id.parent_task_button)).perform(click());
但是点击没有按预期工作。我逐步完成了它(启用 android "Show Taps" 和 "Pointer location" 开发人员设置),结果是测试没有点击以图像按钮为中心,而是点击这里:
...正好在分隔线上,但不在 ImageButton 的中心。
如果我将 ImageButton 替换为普通 Button,则点击正确并且测试有效! 有谁知道这里的问题是什么或如何解决?
我找到了导致问题的行(在 ImageButton 中):
android:rotation="90"
如果我从图像按钮中删除这个旋转,则点击正确地在中间。 所以我的临时解决方法是旋转可绘制对象本身而不是按钮。
我目前也在研究 android espresso 代码并试图找出这里有问题的代码。 似乎点击坐标的计算是错误的,因为它忽略了旋转,因此计算错误。 如果我发现什么,会更新这个 post。