4

Android入门第11天-Android中RadioButton的使用

 1 year ago
source link: https://blog.csdn.net/lifetragedy/article/details/127715196
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Android入门第11天-Android中RadioButton的使用_TGITCIC的博客-CSDN博客

我们在开发中经常会面临:想做一下这样的一个功能。

fa4d735615144be7af00170f6ddee6c7.png

在本篇中我们就来实现RadioButton,当然,本篇中的控件是hard code的,我们有时在开发中经常还会碰到需要通过后台service动态渲染一些组件。我们会在稍后的篇章中讲到如何根据后台service返回后动态渲染组件并把组件的值和后台表、存储内的ID做联动。

为此我们需要使用RadioGroup和RadioButton。

此注需要注意的点是:

  1. 把两个RadioButton套到RadioGroup里,并对这3个对象都要设置ID且必须设置ID,否则会变成:你在切换RadioButton时,另一个RadioButton还处于被选中状态。
  2. 另外,RadioGroup里的orientation后的vertical或者是horizontal决定了RadioButton是“坚排”还是“横排”。
  3. 单个RadioButton里的layout_marginRight=""的值决定了,每个radiobutton间的间隔是多少。

界面端代码


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK