android - 使用覆盖 View 避免背景小部件事件

标签 android android-layout

看看下面的截图。

Layout

在此布局中,我显示覆盖 View (粉红色的 View )以禁用登录按钮单击,直到加载完成。但问题是,虽然覆盖 View 出现在登录按钮上方,但仍然调用登录按钮点击。知道这里发生了什么吗?

以下是我的叠加 View xml。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#88ff0000">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/loader_bg">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Just a moment..."
        android:textSize="12dp"
        android:textColor="#000000"
        android:layout_margin="10dp"
        android:layout_gravity="center_horizontal"/>

    <ProgressBar android:id="@android:id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="?android:progressBarStyleSmall"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_gravity="center_horizontal"
        android:indeterminateDrawable="@drawable/loading_wheel"/>
        </LinearLayout>

</RelativeLayout>

最佳答案

我自己解决了。

如果没有实现覆盖事件,Android 会将事件分派(dispatch)给背景小部件。因此,只需在叠加 View 上添加点击监听器即可避免点击登录按钮。

关于android - 使用覆盖 View 避免背景小部件事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24551122/

相关文章:

java - android studio 使 Colors.xml 损坏,然后发生未知错误

android - 为三星商店转换 Google Play 中的 android 应用程序

android - 谷歌地图自定义标记图标,在 Android 上具有集群功能

android - 使用 MPAndroidChart 绘制时间序列图

android - 如何将文本放在 Button 或 ImageButton 下方?

Intent 返回 Activity 后,android alertdialog 不显示

java - 检查数据库中密码的函数

android - 使用setRotation后如何在linearLayout中刷新match_parent?

android - 在 Android 上保存自定义 View 的屏幕截图

Android动态 fragment 加载进度条可见性不会设置