按键采用文字和图像(Android版) [英] Button with text AND an image (Android)

查看:111
本文介绍了按键采用文字和图像(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与这两个图像和文本创建Android按钮,但文本自动居中。我如何放置文本在按钮的底部?

I want to create an android button with both an image and text, but the text is automatically centered. How do I place the text at the bottom of the button?

我知道我可以使用相对布局来放置图像下方的第二个文本按钮,但我preFER,以尽量减少code。

I know I can use relative layout to place a second text button underneath the image, but I prefer to minimize the code.

推荐答案

如果我是你,我只想不使用按钮。使用的LinearLayout或RelativeLayout的,只是给它的按钮背景(提示:如果你希望它为每个国家不同的图像使用选择器),把你的TextView在它的内部,那么你可以使用drawableLeft,drawableTop等属性把你想要哪一方的画面。如果希望控制的更大的水平的地方的画面的推移相对于文本,然后使用一个TextView的和一个ImageView的。然后,在你的java先手布局的参考和对待它就像你的一个按钮,与setOnClickListener()。

If I were you I would just not use a Button. Use LinearLayout, or RelativeLayout and just give it the Button background(Hint: use a selector if you want it to have different images for each state) and place your TextView inside of it, then you can use the drawableLeft, drawableTop etc.. attributes to put the picture on whichever side you want. If you want a greater level of control as to where the picture goes in relation to the text then use one TextView and one ImageView. Then in your java just get a reference to your layout and treat it just like you would a button, with setOnClickListener().

这篇关于按键采用文字和图像(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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