看看下面的截图。
在此布局中,我显示覆盖 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/