将视图填充到 Button 中?
我在一些论坛上看到这个问题没有得到解答,想知道是否有人知道如何回答。
假设需要一个带有图片和文本的按钮。创建一个 xml 视图然后将其填充到 Button 中似乎很自然。这可能吗?
目前,我不需要按钮看起来可点击或在点击时更改其颜色,但考虑进行充气会如何影响这也可能很有趣。
顺便说一句,我发现这个教程描述了同一问题的解决方案,但他们正在编写一个扩展 View 的类来实现目标。这对我来说似乎有点过分了。 http:// /kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/
提前致谢! 安娜
I saw this questions unanswered on some forums and wonder if anyone have a clue on how to answer.
Let's say for instance a button is needed with a picture and a text. It would seem natural to create an xml view and then inflate it into the Button. Is this possible?
At the moment I don't need the button to look clickable or change it's color at click, but it could also be interesting to consider how this will be affected by making the inflate.
Btw, I found this one tutorial describing a solution to the same problem, but they were writing a class extending View to obtain the goal. That seems a bit overklill to me.
http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/
Thanks in advance!
Anna
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为您的自定义按钮创建一个 XML 布局,其中包含 TextView 和 ImageView。将以下属性放入文件中的根布局:
您将获得所需的内容。
Make a XML layout of your custom Button, that contains the TextView and ImageView. Put the following attributes to the root layout in the file:
and you'll get what you need.