两个重叠的控件响应事件处理

大家是不是有遇到过这样的情况,比如RelativeLayout容器里面,放了两个控件是重叠的状态,但是我想添加点击事件时,我想响应底下的控件,而不是响应上面的控件,如何处理呢?今天我来教大家如何实现。

列代码:

布局文件xml

<RelativeLayout

    android:id="@+id/rl1"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

<TextView

    android:id="@+id/btn_qd"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:text="@string/btn_ok"

    android:textSize="12sp"

    android:textColor="@color/white"

    android:layout_alignParentRight="true"

    android:background="@drawable/shape_shezhi"

    android:layout_marginLeft="20dp"/>

<View

    android:id="@+id/ll_bg"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:clickable="false"

    android:background="#e0000000"

    android:alpha="0.7"

    android:orientation="vertical"/>

</RelativeLayout>

代码里面这样写:

View mllBg = (View)mRlPwdInput.findViewById(R.id.ll_bg);

mllBg.setOnClickListener(null);


解决问题,大功告成,就是把最上面的事件设置为null,就ok了。

如果解决了你的问题,希望能帮我点个赞,你的赞是我最大的动力,谢谢!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容