android如何设置右侧的复选框图标?
我正在制作一个api,其中我在xml文件中使用了复选框。问题是我的复选框图标显示在左侧,但我想将复选框移到右侧文本“男”或“女”附近。这样地。。 但目前我越来越喜欢这种观点 我希望我的checkicon选项位于右侧..,我使用了此代码..这是我的xmlandroid如何设置右侧的复选框图标?,android,xml,checkbox,Android,Xml,Checkbox,我正在制作一个api,其中我在xml文件中使用了复选框。问题是我的复选框图标显示在左侧,但我想将复选框移到右侧文本“男”或“女”附近。这样地。。 但目前我越来越喜欢这种观点 我希望我的checkicon选项位于右侧..,我使用了此代码..这是我的xml 谢谢。在复选框中使用以下属性: Set android:button="@null"; Set android:drawableRight="@drawable/YOUR_CHECKBOX_BUTTON" 希望它能起作用 用这个
谢谢。在复选框中使用以下属性:
Set android:button="@null";
Set android:drawableRight="@drawable/YOUR_CHECKBOX_BUTTON"
希望它能起作用 用这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="68dp"
android:paddingRight="100dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="32dp"
android:text="Male"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_centerHorizontal="true"
android:text="Female"
android:textAppearance="?android:attr/textAppearanceSmall" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView2" />
</RelativeLayout>
最简单的方法是:
<RelativeLayout
android:id="@+id/checkbox_layoyt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/edt_layout"
android:layout_marginTop="34dp" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="31dp"
android:layout_marginTop="43dp"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox2"
android:layout_alignBottom="@+id/checkBox2"
android:layout_toRightOf="@+id/button1"
android:text="@string/male" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_toLeftOf="@+id/checkBox1"
android:text="@string/female" />
</RelativeLayout>
输出是
<RelativeLayout
android:id="@+id/xml_associate_relative_radio_career"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/common_left_right_margin"
android:paddingTop="@dimen/common_left_right_margin" >
<ImageView
android:id="@+id/xml_associate_img_career"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:alignparentRight="true"
android:src="@drawable/sel_radiobtn_click" />
<TextView
android:id="@+id/xml_associate_txt_career"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/xml_associate_img_career"
android:gravity="center_vertical"
android:paddingLeft="@dimen/common_left_right_margin"
android:paddingRight="@dimen/common_padding_left_right"
android:text="@string/associate_career"
android:textColor="@color/common_color_blackdarkergrey"
android:textSize="@dimen/common_font_16sp" />
</RelativeLayout>
请使用此代码..图像视图设置复选框图像..并且您已使用相对布局单击事件。将此设置为您的按钮:
android:drawableRight="@drawable/YOUR_CHECKBOX_BUTTON"
试试这个。。您可以使用CheckedTextView而不是复选框来满足您的需要。。此外,它几乎具有与CheckBox相似的所有属性,因此您也可以通过java选中/取消选中它,而无需使用任何外部可绘制图像,也无需根据不同的条件更改它们的源代码,这可能会证明成本高昂,而且有时会变得一团糟
<RelativeLayout
android:id="@+id/checkbox_layoyt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/edt_layout"
android:layout_marginTop="34dp" >
<CheckedTextView
android:id="@+id/cb_male"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="29dp"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:checked="false"
android:gravity="center"
android:text=" Male"
android:textColor="#000000"
android:textSize="18dp" />
<CheckedTextView
android:id="@+id/cb_female"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/cb_male"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:checked="false"
android:gravity="center"
android:text=" Female"
android:textColor="#000000"
android:textSize="18dp" />
</RelativeLayout>
只需将其添加到复选框XML代码中:
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
这对我很有用。有一个不带文本的复选框,并将文本视图添加到该复选框的右侧。在棒棒糖前的设备上使用AppCompat
主题时,这不允许小部件着色。使用CheckedTextView
似乎没有AppCompat
主题问题-您可以使用?android:attr/listcooiceindicator multiple
用于复选标记
属性,并正确着色。经过大量的尝试和错误才发现这一点。。。
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"