Android:RadioGroup下的嵌套布局中的RadioButton属于Group

前端之家收集整理的这篇文章主要介绍了Android:RadioGroup下的嵌套布局中的RadioButton属于Group前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正试图让我的radiobuttons的一些明智的定位,这是RadioGroup的一部分.我遇到了麻烦,因为我的RadioGroup坐在我的布局设计的其余部分之上,然后我使用边距按下按钮,这里的问题是这只适用于一个或两个设备布局.当我发现我可以定义我的RadioGroup然后放入一个RelativeLayout,其中包含一个RadioButtons,然后我再重复两次时,我以为我敲了金.这给了我想要的布局.问题是,当我运行代码时,RadioButtons行为链接独立按钮:(

那么两个问题,

>我可以将这些按钮链接回集团吗?
>是否有一种不错的方法可以独立于集团定义RadioGroup Radiobuttons的布局.

我在想一个替代方案可能是独立的RadioButtons并使用代码来启用/禁用它们,但这确实有点打败了RadioGroup的用处.

谢谢.

如果你好奇,这是我的XML布局.

  1. <ScrollView android:id="@+id/scrollview"
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:layout_centerHorizontal="true"
  5.  
  6. android:layout_below="@id/HDDResultsBox"
  7. >
  8.  
  9. <RelativeLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:orientation="vertical"
  13. android:focusable="true"
  14. android:focusableInTouchMode="true"
  15. android:windowSoftInputMode="stateHidden"
  16. >
  17.  
  18.  
  19. <RadioGroup android:id="@+id/calcBy"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:orientation="vertical"
  23. android:focusable="true"
  24. android:focusableInTouchMode="true"
  25. android:layout_below="@id/HDDResultsBox"
  26.  
  27. >
  28.  
  29. <RelativeLayout android:id="@+id/intervalBox"
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. android:background="@drawable/backgroundBox"
  33. android:layout_margin="5dp"
  34. android:padding="5dp"
  35.  
  36.  
  37. >
  38. <TextView android:id="@+id/intervalHeader"
  39. android:layout_width="wrap_content"
  40. android:layout_height="wrap_content"
  41. android:text="Interval"
  42. android:gravity="left"
  43. android:textColor="#ffffff"
  44. android:textStyle="bold"
  45. android:layout_marginLeft="5dp"
  46. />
  47.  
  48. <TextView android:id="@+id/intervalHelpText"
  49. android:layout_width="wrap_content"
  50. android:layout_height="wrap_content"
  51. android:text="Interval help text"
  52. android:gravity="left"
  53. android:textColor="#ffffff"
  54. android:textSize="8dp"
  55. android:layout_toRightOf="@id/intervalHeader"
  56. android:layout_marginLeft="10dp"
  57. />
  58.  
  59. <LinearLayout android:id="@+id/interval2ndBox"
  60. android:layout_width="match_parent"
  61. android:layout_height="wrap_content"
  62. android:orientation="horizontal"
  63. android:layout_below="@id/intervalHeader"
  64. android:layout_marginLeft="10dp"
  65. >
  66. <RadioButton android:id="@+id/byInterval"
  67. android:layout_width="wrap_content"
  68. android:layout_height="wrap_content"
  69. android:layout_marginTop="2dp"
  70. />
  71.  
  72. <EditText android:id="@+id/intervalValue"
  73. android:layout_width="75dp"
  74. android:layout_height="40dp"
  75. android:text="50"
  76. android:textSize="14sp"
  77. android:gravity="center"
  78. android:inputType="number"
  79. android:layout_marginLeft="20dp"
  80. />
  81.  
  82. <Spinner android:id="@+id/intervalType"
  83. android:layout_width="match_parent"
  84. android:layout_height="42dp"
  85. android:drawSelectorOnTop="false"
  86. android:layout_marginTop="1dp"
  87. android:layout_marginLeft="10dp"
  88. android:layout_weight="10"
  89. android:layout_marginRight="2dp"
  90. />
  91.  
  92. <SeekBar android:id="@+id/intervalSeek"
  93. android:layout_width="match_parent"
  94. android:layout_height="wrap_content"
  95. android:max="100"
  96. android:progress="50"
  97. android:layout_marginLeft="5dp"
  98. android:layout_marginRight="5dp"
  99. android:layout_marginTop="8dp"
  100. android:layout_weight="7"
  101. />
  102. </LinearLayout>
  103.  
  104. </RelativeLayout>
  105.  
  106.  
  107. <RelativeLayout android:id="@+id/recordBox"
  108. android:layout_width="match_parent"
  109. android:layout_height="wrap_content"
  110. android:background="@drawable/backgroundBox"
  111. android:layout_margin="5dp"
  112. android:padding="5dp"
  113.  
  114.  
  115. >
  116. <TextView android:id="@+id/recordHeader"
  117. android:layout_width="wrap_content"
  118. android:layout_height="wrap_content"
  119. android:text="Record Duration"
  120. android:gravity="left"
  121. android:textColor="#ffffff"
  122. android:textStyle="bold"
  123. android:layout_marginLeft="5dp"
  124. />
  125.  
  126. <TextView android:id="@+id/recordHelpText"
  127. android:layout_width="wrap_content"
  128. android:layout_height="wrap_content"
  129. android:text="Record help text"
  130. android:gravity="left"
  131. android:textColor="#ffffff"
  132. android:textSize="8dp"
  133. android:layout_toRightOf="@id/recordHeader"
  134. android:layout_marginLeft="10dp"
  135. />
  136.  
  137. <LinearLayout android:id="@+id/record2ndBox"
  138. android:layout_width="match_parent"
  139. android:layout_height="wrap_content"
  140. android:orientation="horizontal"
  141. android:layout_below="@id/recordHeader"
  142. android:layout_marginLeft="10dp"
  143. >
  144. <RadioButton android:id="@+id/byrecord"
  145. android:layout_width="wrap_content"
  146. android:layout_height="wrap_content"
  147. android:layout_marginTop="2dp"
  148. />
  149.  
  150. <EditText android:id="@+id/recordValue"
  151. android:layout_width="75dp"
  152. android:layout_height="40dp"
  153. android:text="50"
  154. android:textSize="14sp"
  155. android:gravity="center"
  156. android:inputType="number"
  157. android:layout_marginLeft="20dp"
  158. />
  159.  
  160. <Spinner android:id="@+id/recordType"
  161. android:layout_width="match_parent"
  162. android:layout_height="42dp"
  163. android:drawSelectorOnTop="false"
  164. android:layout_marginTop="1dp"
  165. android:layout_marginLeft="10dp"
  166. android:layout_weight="10"
  167. android:layout_marginRight="2dp"
  168. />
  169.  
  170. <SeekBar android:id="@+id/recordSeek"
  171. android:layout_width="match_parent"
  172. android:layout_height="wrap_content"
  173. android:max="100"
  174. android:progress="50"
  175. android:layout_marginLeft="5dp"
  176. android:layout_marginRight="5dp"
  177. android:layout_marginTop="8dp"
  178. android:layout_weight="7"
  179. />
  180. </LinearLayout>
  181.  
  182. </RelativeLayout>
  183.  
  184. <RelativeLayout android:id="@+id/playBackBox"
  185. android:layout_width="match_parent"
  186. android:layout_height="wrap_content"
  187. android:background="@drawable/backgroundBox"
  188. android:layout_margin="5dp"
  189. android:padding="5dp"
  190.  
  191.  
  192. >
  193. <TextView android:id="@+id/playBackHeader"
  194. android:layout_width="wrap_content"
  195. android:layout_height="wrap_content"
  196. android:text="Video Length"
  197. android:gravity="left"
  198. android:textColor="#ffffff"
  199. android:textStyle="bold"
  200. android:layout_marginLeft="5dp"
  201. />
  202.  
  203. <TextView android:id="@+id/playBackHelpText"
  204. android:layout_width="wrap_content"
  205. android:layout_height="wrap_content"
  206. android:text="playBack help text"
  207. android:gravity="left"
  208. android:textColor="#ffffff"
  209. android:textSize="8dp"
  210. android:layout_toRightOf="@id/playBackHeader"
  211. android:layout_marginLeft="10dp"
  212. />
  213.  
  214. <LinearLayout android:id="@+id/playBack2ndBox"
  215. android:layout_width="match_parent"
  216. android:layout_height="wrap_content"
  217. android:orientation="horizontal"
  218. android:layout_below="@id/playBackHeader"
  219. android:layout_marginLeft="10dp"
  220. >
  221. <RadioButton android:id="@+id/byplayBack"
  222. android:layout_width="wrap_content"
  223. android:layout_height="wrap_content"
  224. android:layout_marginTop="2dp"
  225. />
  226.  
  227. <EditText android:id="@+id/playBackValue"
  228. android:layout_width="75dp"
  229. android:layout_height="40dp"
  230. android:text="50"
  231. android:textSize="14sp"
  232. android:gravity="center"
  233. android:inputType="number"
  234. android:layout_marginLeft="20dp"
  235. />
  236.  
  237. <Spinner android:id="@+id/playBackType"
  238. android:layout_width="match_parent"
  239. android:layout_height="42dp"
  240. android:drawSelectorOnTop="false"
  241. android:layout_marginTop="1dp"
  242. android:layout_marginLeft="10dp"
  243. android:layout_weight="10"
  244. android:layout_marginRight="2dp"
  245. />
  246.  
  247. <SeekBar android:id="@+id/playBackSeek"
  248. android:layout_width="match_parent"
  249. android:layout_height="wrap_content"
  250. android:max="100"
  251. android:progress="50"
  252. android:layout_marginLeft="5dp"
  253. android:layout_marginRight="5dp"
  254. android:layout_marginTop="8dp"
  255. android:layout_weight="7"
  256. />
  257. </LinearLayout>
  258.  
  259. </RelativeLayout>
  260.  
  261.  
  262. </RadioGroup>
  263. </RelativeLayout>
  264. </ScrollView>

解决方法

在寻找解决方案后,它看起来唯一的方法是使用单独的单选按钮,然后以编程方式控制开/关状态.

猜你在找的Android相关文章