使 LinearLayout 像一个按钮 [英] Making a LinearLayout act like an Button

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

问题描述

我有一个 LinearLayout,我将它的样式设置为一个 button,它包含一些 text/ImageView 元素.我想让整个 LinearLayout 表现得像一个 button,特别是赋予它在 a 中定义的状态,以便在按下时具有不同的背景.

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 绝对是整个 Layout 和定位的大小更好的方法?

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天全站免登陆