制作的LinearLayout的行为像一个按钮 [英] Making a LinearLayout act like an Button

查看:171
本文介绍了制作的LinearLayout的行为像一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的风格,看起来像一个按钮的LinearLayout,它包含了一些文本/ ImageView的元素。我想使整个的LinearLayout行为就像一个按钮,特别是给它指出,在一个如此定义它时,它是pressed不同的背景。

I have a LinearLayout that I've styled to look like a button, and it contains a few text/ImageView elements. I would like to make the whole LinearLayout act like a button, in particular to give it states that are defined in a so it has a different background when it is pressed.

难道还有比作出的ImageButton整个布局的大小和定位绝对更好的办法?

Is there a better way than making an ImageButton the size of the whole Layout and positioning absolutely?

推荐答案

我就遇到了这个问题,刚才。你必须给的LinearLayout设置为可点击。你可以做到这一点的XML与

I ran into this problem just now. You'll have to set the LinearLayout to clickable. You can either do this in the XML with

android:clickable="true"

或与

yourLinearLayout.setClickable(true);

干杯!

这篇关于制作的LinearLayout的行为像一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆