rajshree rajshree - 18 days ago 9
Android Question

android how to set checkbox icon on rightside?

i am making an api in which i am using checkbox in my xml file.the problem is that my checkbox icons are showing on left side.,but i want to move my checkbox on right side near text "male" or"female". like this..
enter image description here

but currently i am getting like this view..

enter image description here

i want my checkicon option on rightside..,i have used this code..here is my xml..




<RelativeLayout
android:id="@+id/header_layout"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#43A6E5" >

<TextView
android:id="@+id/tv_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Earn 1 PTS for every Chat you Receive"

android:textColor="#FFF200"
android:textSize="18dp" />
</RelativeLayout>

<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="6dp"
android:layout_below="@+id/header_layout"
android:layout_centerHorizontal="true"
android:background="#46B1F6" />

<RelativeLayout
android:id="@+id/edt_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view1"
android:background="#46B1F6" >

<EditText
android:id="@+id/et_mail"
style="@style/EdittextStyle"
android:layout_alignLeft="@+id/et_name"
android:layout_alignRight="@+id/et_name"
android:layout_below="@+id/et_name"
android:background="@drawable/rounded_edittext"
android:text=" Your Email" >

<requestFocus />
</EditText>

<Spinner
android:id="@+id/spinner1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_alignLeft="@+id/et_mail"
android:layout_below="@+id/et_mail"
android:layout_marginTop="33dp"
android:background="@drawable/rounded_edittext" />

<EditText
android:id="@+id/editText1"
style="@style/EdittextStyle"
android:layout_alignBottom="@+id/spinner1"
android:layout_alignRight="@+id/et_mail"
android:layout_marginLeft="14dp"
android:layout_toRightOf="@+id/spinner1"
android:background="@drawable/rounded_edittext"
android:text=" Your Phone"
android:textColor="#ffffff" />

<EditText
android:id="@+id/et_name"
style="@style/EdittextStyle"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="29dp"
android:background="@drawable/rounded_edittext"
android:text=" Your Name" />

<!-- android:background="@drawable/rounded_edittext" /> -->

</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/cb_male"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="29dp"
android:background="@drawable/rounded_edittext"
android:text=" Male"
android:textColor="#ffffff"
android:textSize="18dp" />


<CheckBox
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:background="@drawable/rounded_edittext"
android:text=" Female"
android:textColor="#ffffff"
android:textSize="18dp" />
</RelativeLayout>

<Button
android:id="@+id/button1"
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_below="@+id/checkbox_layoyt"
android:layout_centerHorizontal="true"
android:layout_marginTop="27dp"
android:background="@drawable/mybutton"
android:gravity="center"
android:text="Create Account"
android:textColor="#ffffff"
android:textSize="22dp" />

<TextView
android:id="@+id/textview_agree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="I agree to the terms and conditions"
android:textColor="#ffffff"
android:textSize="14dp" />




Thankyou..

Answer
 <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>

please use this code.....imageview set checkbox image..and you have using relative layout click event.

Comments