Android的添加图像按钮 [英] Android add image to button
问题描述
我要的图像添加到按钮
(没有的ImageButton
,由于特定的按钮可以包含文本或图像;加上的ImageButton有同样的问题),同时仍保留了原生Android样式的按钮。所以加入的android:背景
在XML不削减,因为这将与圆角等删除Android的默认按钮(android.R .drawable.btn_default)
I want to add an image to a Button
(no imagebutton
, as the particular button can either contain text or an image; plus the imagebutton has the same problem), while still retaining the original android-style button. So adding android:background
in the XML doesn't cut it, as that will remove the android default button with rounded corners etc. (android.R.drawable.btn_default)
这是在任何可能的方式?
Is this in any way possible?
我想一个办法就是让 9patch
图像(一个用于和一个向下)按钮pressed和 onTouch ACTION_DOWN
使分层背景绘制,并将该到按钮,做同样的事情,但与另一个 9patch
为 onTouch Action_UP
,但我认为,这将大大降低应用程序的性能,这将需要相当多的资源阅读和图层合并为所有的按钮点击(和我的应用程序,那将是相当很多)。就是我上面的陈述正确?
I think one way is to make a 9patch
image for the button pressed (one for up and one for down) and onTouch Action_DOWN
make a layered background drawable and put that onto the button, and doing the same thing but with another 9patch
for onTouch Action_UP
, but I think that will decrease the performance of the application substantially, as that will require quite a lot of resource reading and layer merging for all the button clicks (and for my application, that will be quite a lot). Is what I state above correct?
编辑:我不能声明图像的源中的XML,因为我从Web服务获得的图像,所以任何事情都有可能上的按钮放,但它以编程方式发生
I can't declare the source of the image in the XML, because I get the images from a web service, so anything can be put on the Buttons, but it has to happen programmatically.
推荐答案
这可以使用机器人完成:drawableTop
,的android:drawableBottom
,的android:drawableLeft
,的android:drawableRight
在layout.xml属性。
This can be done using the android:drawableTop
, android:drawableBottom
, android:drawableLeft
, android:drawableRight
attributes in your layout.xml.
这篇关于Android的添加图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!