默认情况下,android复选框在右侧显示文本,在左侧显示复选框
我想在右侧显示复选框并在左侧显示文本
我该如何实现这一点?
发布于 2010-07-01 18:10:55
我想不出样式的方法,但您可以将checkbox的文本设置为空,然后在checkbox的左侧放置一个包含所需文本的TextView。
发布于 2014-02-24 23:01:31
我认为现在回答这个问题为时已晚,但实际上有一种方法可以实现你的目标。您只需在您的复选框中添加以下行:
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
您也可以使用自定义的可绘制复选框。
对于radioButton:
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
如果你想以编程的方式来完成:
定义一个布局并将其命名为RightCheckBox,然后复制以下行:
<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:text="hello"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"/>
当您需要以编程方式添加它时,只需将其扩展为CheckBox并将其添加到根视图中。
CheckBox cb = (CheckBox)((LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.check_right_checkbox,null);
rootView.addView(cb);
发布于 2017-06-12 17:50:03
你可以做到
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|center"//or "center_vertical" for center text
android:layoutDirection="rtl"
android:text="hello" />
下面这行就足够了
android:layoutDirection="rtl"
https://stackoverflow.com/questions/3156781
复制相似问题