Set Checkbox align right side of Textview in android XML

How to show textview left side position of checkbox in android application using xml.

In this tutorial we are simply creating three textview and three Checkbox now after that we are setting up check box position to right side of textview so they look same and the textview text represents the Checkbox value. Because by default when we add custom text into checkbox then it will set on right side of check box but with this functionality layout settings the check box text will appears at the left side of textview. So here is the complete step by step tutorial for Set Checkbox align right side of Textview in android XML.

android-project-download-code-button

How to Set Checkbox align right side of Textview in android XML.

Code for MainActivity.java file.

package com.checkbox_align_rightsidetextview_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }

}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.checkbox_align_rightsidetextview_android_examples.com.MainActivity" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentTop="true"
 android:text="TextView-1"
 android:textAppearance="?android:attr/textAppearanceMedium" />

 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/textView1"
 android:layout_below="@+id/textView1"
 android:layout_marginTop="20dp"
 android:text="TextView-2"
 android:textAppearance="?android:attr/textAppearanceMedium" />

 <TextView
 android:id="@+id/textView3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/textView2"
 android:layout_below="@+id/textView2"
 android:layout_marginTop="20dp"
 android:text="TextView-3"
 android:textAppearance="?android:attr/textAppearanceMedium" />

 <CheckBox
 android:id="@+id/checkBox1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@+id/textView1"
 android:layout_alignBottom="@+id/textView1"
 android:layout_marginLeft="16dp"
 android:layout_toRightOf="@+id/textView1" />

 <CheckBox
 android:id="@+id/checkBox2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@+id/textView2"
 android:layout_alignBottom="@+id/textView2"
 android:layout_alignLeft="@+id/checkBox1" />

 <CheckBox
 android:id="@+id/checkBox3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@+id/textView3"
 android:layout_alignBottom="@+id/textView3"
 android:layout_alignLeft="@+id/checkBox2" />

</RelativeLayout>

Screenshot:

Set Checkbox align right side of Textview in android XML

Click here to download Set Checkbox align right side of Textview in android XML project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *