How to show android checkbox at right side?
I can't think of a way with the styling, but you could just set the text of the checkbox to nothing, and put a TextView to the left of the checkbox with your desired text.
How can I align checkbox with text to right side of the screen?
Attribute android:gravity
is working on view itself, while android:layout_gravity
is suggestion for parent view to align it's child.
if you want tell parent layout to align it's child at left or right you have two options:
- use
android:gravity
on parent, and thus parent will try to align all child views at that gravity. android:layout_gravity
on child view, and only this view will try to align itself in that gravity.
How to Set the Checkbox on the right side of the text
I dont know whether it is possible or not by styling ,
But here is a solution for you
Use ""
as the value of the CheckBox
,then add a TextView
to the left of the CheckBox
with your desired text.
Align text left, checkbox right
Since you are already using a RelativeLayout, make use of it's attributes:
Remove android:gravity
from the children and replace them with android:layout_alignParentLeft="true"
for the TextView and android:layout_alignParentRight="true"
for the CheckBox.
That positions the children relative to the parents borders. You may also want to add android:layout_centerVertical="true"
to each child to center the two vertical within each list item.
For further options and attributes see the documentation.
How to align check box on the right side in CheckedtextView
Following code is working for me
<CheckedTextView
android:id="@+id/checkedTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#000000,"
android:layout_marginTop="48dp"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:checked="true"
android:text="CheckedTextView" />
Align checkbox to the right side in LinearLayout android
You can use the layout_weight
attribute on your TextView
only to automatically designate the TextView
to fill any space which the CheckBox
does not occupy. For example, the following will set your checkboxes to the end (provided they have no text associated with them) and then lets the TextView fill the rest of the layout.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:id="@+id/itemTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<CheckBox
android:id="@+id/checkItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Additionally, you should use match_parent
instead of fill_parent
as fill_parent
is deprecated.
android how to set checkbox icon on rightside?
<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.
How to create a Check Box which has the text in left and box in right?
You could do what Slartibartfast suggested or create a checkbox with a label of "" and add a separate TextView to the left if that doesn't suit your fancy.
CheckBox widget in the top right corner of an image
My comment its mean like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="" />
</RelativeLayout>
</LinearLayout>
Related Topics
Adb Is Not Recognized as Internal or External Command on Windows
Android Get Screenshot of All Listview Items
Android: Radiogroup - How to Configure the Event Listener
Firebase @Propertyname Doesn't Work
Android Studio - How to Make an Avd with Arm Instead of Haxm
Android: Retrieve Contact Name from Phone Number
Appcompatactivity.Oncreate Can Only Be Called from Within the Same Library Group
How to Set Text in an Edittext
How to Style the Standard React-Native Android Picker
Android Broadcastreceiver, Auto Run Service After Reboot of Device
Programmatically Obtain the Android API Level of a Device
How to Access Fragment's Child Views Inside Fragment's Parent Activity
Android Mediaplayer Throwing "Prepare Failed.: Status=0X1" on 2.1, Works on 2.2
Gradle Dsl Method Not Found: 'Compile()'
Trying to Get the Display Size of an Image in an Imageview
Android Runonuithread Explanation