<LinearLayout android:descendantFocusability="blocksDescendants">
<Button android:background="@layout/selector" >
</LinearLayout>
Button通过设置android:background使得点击时变换背景颜色
但如何实现点击LinearLayout时会触发Button的onClick(就是Button的背景颜色也会变化)
------解决方案--------------------
觉得你这联动不能用selector,考虑考虑设计上吧
------解决方案--------------------
别用selector,在代码中添加ontouch事件试一下
------解决方案--------------------
为什么不换个思路呢? 把按钮做大一点,不需要方法图片,只是在图片周围留白
------解决方案--------------------
其实你的思路太局限了,imageView和button都是View,大家都有同样的基类,那干嘛一定要用button呢,而且也根本没必要去监听button的OnClick。
你把Button换成imageView(不换也可以,但是可扩展性不好),然后LinearLayout和imageView都做一个selector,给LinearLayout做一个OnClick监听,绑定在xml里就行了,然后监听里加一行
你的LinearLayout.setSelected(true)就可以了
------解决方案--------------------
Button换成View然后只要给LinearLayout写onClick事件就可以了
------解决方案--------------------
你是不是LinearLayout的Clickable没有设置为true啊
或者写onTeachlistener也可以