您的位置:首页 > 其它

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

2016-08-20 10:38 549 查看

场景分析 :

在开发过程中,避免一个控件的太小,不方便用户点击,我们一般会给控件设置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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐