解决父布局具有点击效果,但是子布局的Button不响应点击事件的问题

场景分析 :

在开发过程中,避免一个控件的太小,不方便用户点击,我们一般会给控件设置padding;

当多个控件响应同一个点击效果的时候,我们的解决方案:
1.将多个控件转化为一个控件,然后设置padding【比如:图片和文字的结合,可以通过TextView和Button的 android:drawableXxx=”“来添加图片】;

2.给这多个控件添加一个父布局,将点击事件赋给父布局即可。
但是问题又来了,如果子控件本身具有点击效果,如Button,ImageButton,父控件的点击效果在子控件的区域会失效【解决方案:将子布局改为自身不具有点击效果的控件,如TextView】

 <LinearLayout
        android:id="@+id/ppt_exit_linear"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:alpha="1"
        android:gravity="center"
        android:onClick="onClick"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/ppt_exit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:drawablePadding="10dp"
            android:drawableTop="@drawable/selector_pager_close"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="@string/close_bt"
            android:textColor="@color/selector_photo_text_color" />
    </LinearLayout>
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值