安卓:结合文字和放大器;上一个按钮或ImageButton的图像 [英] Android: combining text & image on a Button or ImageButton

查看:147
本文介绍了安卓:结合文字和放大器;上一个按钮或ImageButton的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个形象(如背景)上的按钮和动态添加,这取决于在运行时,上面的/在图像上的一些文字。

I'm trying to have an image (as the background) on a button and add dynamically, depending on what's happening during run-time, some text above/over the image.

如果我使用的ImageButton 我甚至不具备添加文本的可能性。 如果我使用按钮我可以添加文本,但只能定义一个图像的安卓drawableBottom 的和类似的XML属性定义的<一个href="http://developer.android.com/reference/android/widget/TextView.html#attr_android%3adrawableBottom">here.

If I use ImageButton I don't even have the possibility to add text. If I use Button I can add text but only define an image with android:drawableBottom and similar XML attributes as defined here.

但这些属性只能结合文字和放大器;图像在x和y的尺寸,这意味着我可以绘制图像在我的文字,但不低于/在我的文字(定义为走出显示器的Z轴)。

However these attributes only combine text & image in x- and y-dimensions, meaning I can draw an image around my text, but not below/under my text (with the z-axis defined as coming out of the display).

这是如何做到这一点有什么建议?其中一个想法是要么延长按钮的ImageButton 并覆盖画() - 方法。但我目前的知识水平我真的不知道如何做到这一点(2D渲染)。也许有人有更多的经验,知道一个解决方案或至少一些指针开始?

Any suggestions on how to do this? One idea would be to either extend Button or ImageButton and override the draw()-method. But with my current level of knowledge I don't really know how to do this (2D rendering). Maybe someone with more experience knows a solution or at least some pointers to start?

推荐答案

您可以致电 setBackgroundDrawable()按钮设置按钮的背景。

You can call setBackgroundDrawable() on a Button to set the background of the button.

任何文本将出现在背景之上。

Any text will appear above the background.

如果您正在寻找在XML类似的东西有: 机器人:背景属性,它的工作方式相同

If you are looking for something similar in xml there is: android:background attribute which works the same way.

这篇关于安卓:结合文字和放大器;上一个按钮或ImageButton的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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