0
点赞
收藏
分享

微信扫一扫

Android各类View触摸监听器失效

豆丁趣 2023-11-13 阅读 43
android

在XML布局中出现重叠的View,位置靠后定义的View会覆盖住位置靠前的View;即靠后的View会拦截触碰事件导致靠前的View无法收到触碰事件,无法触发监听器。

//例.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout ... ...>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout_1" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout_2"/>

</androidx.constraintlayout.widget.ConstraintLayout>

// layout_2会覆盖住layout_1;导致layout_1无法接收到触摸事件
举报

相关推荐

0 条评论