Android 扩展视图,特别是 RadioButton
我正在尝试实现一个 RadioButton,其右上角有一个 TextView,如下所示:
一旦我单击应用程序中的某些内容,文本视图将保存一个数字。
我知道我必须扩展 RadioButton 并以某种方式在其中添加 TextView,但我不太明白如何做。我希望能够在 xml 中配置按钮的所有方面(textview 的背景、textview 是否可见等)。
我该怎么办?我从哪里开始?
I'm trying to implement a RadioButton that has a TextView on the top right part of it, like so:
The Textview will hold a number, once I've clicked something in the app.
I understand that I will have to extend RadioButton and add a TextView in there somehow, but I don't really understand how. I'd like to be able to configure all aspects of the button in xml (background of textview, if textview is visible and so on).
How do I go about this? Where do I start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)您需要确保它最终会像单选按钮一样起作用,无论您做什么,都要确保您的 radioButton 可以添加到 RadioGroup 中。
2)本教程将为您提供一些创建自定义组件的技巧
http://hugman.posterous.com/parameterizing-a-custom-components -推广
和
http://developer.android.com/guide/topics/ui/custom -components.html
3) 如果您想在 XML 编辑器中编辑属性,则需要为接受 XML 属性的自定义按钮创建一个构造函数
4) 如果您只想内联执行此操作,请在布局中添加一个单选按钮和一个文本框在你想要的地方。将布局上的所有触摸事件传递给单选按钮 sp,它会在触摸时切换,并将布局添加到您的 RadioGroup(需要一些调整)。
1) You need to make sure it eventually will act and behave like a radio button, what ever you do make sure your radioButton can be added to RadioGroup.
2) This tutorial will give you some tips on creating custom components
http://hugman.posterous.com/parameterizing-a-custom-components-to-promote
and
http://developer.android.com/guide/topics/ui/custom-components.html
3) If you want to edit the properties in XML editor, you need to create a constructor for your custom button that accepts XML attributes
4) If you simply want to do this inline, in a Layout add a radioButton and a textBox where ever you want. Pass all the touch events on the layout to the radio button sp that it toggles on touch and add the Layout to your RadioGroup(will need a little tweaking).