我想知道是否有切换文本出现在android单选按钮上的边的方法?更改文本出现在单选按钮上的边
回答
正如Ravi Vyas所示,您可以使用TextView
和RadioButton
自己完成此操作。 RadioButton
没有什么内在的东西来重新定位按钮相对于文本,从我的源代码阅读。
此外,请记住,仅仅因为这可能并不意味着这是一个好主意。例如,在iPhone上,如果您太过于混淆您的应用,则可能不允许发布您的应用,因为它们具有应用必须遵守的人机界面准则。 Android给了你更多的绳索 - 不要让你的用户挂在它上面。
我想做同样的事情,而不必又扩展另一个类(或两个,因为你将不得不至少延长CompoundButton 和单选)的东西,应该是从一开始就执行工作的一部分。因为我使用的是RadioGroup,如果你在布局容器中放置RadioButton和TextView,它将不起作用。毫无疑问,我的解决方案有点冒失,但 - 它的工作原理。
1)设置填充留给40 2)设置布局保证金留给-36dp
此时,原来的单选按钮将视图外,和你的文本视图会坐在最左边有4dp的余量。
3)设置为@android可绘制权:可绘制/ btn_radio
现在你必须在左侧文字和右侧的按钮,本地单选按钮,将与一个RadioGroup中工作。
@CommonsWare
值得一提的是,这是令人难以置信的讽刺带来了人机界面指南针对这一特定问题。尤其是考虑到调整RadioButton布局以将按钮放置在最右侧,将与Spinner菜单的布局保持一致。我完全同意你对此事的看法 - 但NickTFried很有可能试图弥补Android在这方面的“悬挂”问题。
您可以使用android:button =“@ null”删除左侧单选按钮(而不是步骤1) – EtienneSky 2012-06-20 06:29:23
当我设置android:按钮=“@ null”,单选按钮没有被检查(点击)。我做错了什么。请帮助http://stackoverflow.com/questions/28052820/android-custom-radio-button-not-getting-checked – 2015-01-20 18:54:44
这可以使用CheckedTextView
;请参阅android RadioButton option on the right side of the text
链接不提供任何额外的信息.... – Jeroen 2013-10-21 23:06:24
如果您使用单个“单选按钮”,CheckedTextView
可正常工作。
但我需要保留一个组中的单选按钮中的触发功能,所以这对我更好地工作:
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:gravity="left|center_vertical"
android:layout_marginLeft="-32dp"
android:text="Radio Button 1" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:gravity="left|center_vertical"
android:layout_marginLeft="-32dp"
android:text="Radio Button2" />
</RadioGroup>
根据需要调整android:layout_marginLeft
。
对于RTL语言i。ËArabic
使用:
<RadioGroup
android:id="@+id/rgNewsFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rbAllNews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-32dp"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:gravity="right|center_vertical"
android:text="ذنيسبمنشخصث"
android:textColor="#ffffff" />
<RadioButton
android:id="@+id/rbMyTeam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-32dp"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:gravity="right|center_vertical"
android:text="تشسيبتسيتبتسيب"
android:textColor="#ffffff" />
</RadioGroup>
的Android有一个内置的布局,你可以使用 - android.R.layout.simple_list_item_single_choice
:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
如果要修改它,你可以在上面的复制粘贴到一个新的XML文件,然后使用<include>
标签将其包含在其他布局中(在Apache 2.0 License下)。您也可以将它用作列表项目,并保持不变。
- 1. Javascript更改单选按钮的文本
- 2. 单选按钮更改提交文本
- 3. 单选按钮更改文本颜色
- 4. 更改按钮上的文本按钮单击无限次
- 5. 基于单选按钮值更改提交按钮文本
- 6. 更改单选按钮上的标签
- 7. 单选按钮只呈现单选按钮而不是文本
- 8. 在Android上更改按钮文本
- 9. 添加课程并在选中时更改单选按钮上的文本
- 10. 文本没有出现,而选中的单选按钮
- 11. jQuery更改选择框上的单选按钮更改
- 12. 更改复选框和单选按钮的边框颜色
- 13. 选中时更改单选按钮的边框颜色
- 14. 更改单选按钮的状态更改复选框的文本
- 15. ASP.NET单选按钮更改
- 16. 单选按钮更改
- 17. 更改单选按钮值
- 18. 更改按钮上文本的方向
- 19. 文本框出现在单选按钮检查
- 20. Woocommerce:更改订单按钮上的文本[已更新]
- 21. 的Android文本菜单更改按钮上的文字
- 22. UICollectionViewCell按钮单击并更改单元格上的文本
- 23. jQuery - 在单选按钮上更新div中的文本
- 24. 检查并更改单选按钮组中的单选按钮
- 25. 使用其他单选按钮更改单选按钮的值
- 26. 每次单击按钮时更改多个单选按钮文本:android
- 27. PDF表单按钮边框更改(Acrobat)
- 28. 在其他按钮上更改按钮文本android
- 29. 在所有按钮上更改停止按钮文本
- 30. 边境的单选按钮
以及可以使文本和未标记的单选按钮的复杂布局 – 2010-04-13 19:01:13