Android ConstraintLayout 点击事件阻止透传 - 详细教程
"android 如何让上层ConstraintLayout 点击事件不透传"\n要让上层的 ConstraintLayout 不透传点击事件,可以在上层的 ConstraintLayout 上设置一个空的点击事件监听器,阻止点击事件的传递。具体步骤如下:\n\n1. 在上层的 ConstraintLayout 的 XML 布局文件中,给 ConstraintLayout 添加一个空的点击事件监听器:\n\nxml\n<androidx.constraintlayout.widget.ConstraintLayout\n android:id="\@+id/upperLayout\"\n android:layout_width="match_parent\"\n android:layout_height="match_parent\"\n android:onClick="onUpperLayoutClicked">\n <!-- other views -->\n\n</androidx.constraintlayout.widget.ConstraintLayout>\n\n\n2. 在与上层 ConstraintLayout 相关的 Activity 或 Fragment 中,添加一个空的点击事件处理方法:\n\njava\npublic void onUpperLayoutClicked(View view) {\n // do nothing\n}\n\n\n这样,当点击上层 ConstraintLayout 时,点击事件将被上层的空的点击事件监听器处理,从而阻止了点击事件的传递。
原文地址: https://www.cveoy.top/t/topic/mC3n 著作权归作者所有。请勿转载和采集!