Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align text left, checkbox right

I'm trying to create a layout for a ListView, with a checkbox to the right and some text to the left. The checkbox should be aligned all the way to the right and the TextView aligned all the way to left of the row, eg:

 ------------------------  text            checkbox  ------------------------  text            checkbox  ------------------------  text            checkbox  ------------------------ 

This is what I have so far:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"       android:layout_width="fill_parent"       android:layout_height="fill_parent"       android:orientation="vertical"       android:paddingLeft="5dip"       android:paddingRight="5dip"       android:paddingTop="8dip"      android:paddingBottom="8dip" >  <TextView       android:id="@+id/text"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:gravity="left"  />  <CheckBox      android:id="@+id/chekcbox"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:gravity="right"   />    </RelativeLayout> 

However, what actually renders is the TextBox is overlaying the checkbox, to the left of the row.

like image 235
Kris B Avatar asked Nov 03 '11 00:11

Kris B


People also ask

Should checkbox be left or right of text?

Generally, the label is placed to the right of the control by the designer. What you're sensing is most likely the rationale. There are no gaps between labels and controls in this layout when you use checkboxes with varying labels lengths.

How can I get checkbox and label on same line?

Method 1: By making the position of checkbox relative, set the vertical-align to the middle can align the checkboxes and their labels. Here, we have made the position of the checkbox relative to the label. So the checkboxes are aligned according to the label.

Which of the following command will align the text to the left of the actual checkbox?

If this property is set to TextAlign. Left , the text is displayed to the left of the check box.

How do I align a checkbox horizontally?

Set the checkbox horizontally by including the data-type = "horizontal" to the fieldset. You can select the checkbox button more than one at a time.


1 Answers

And to get the checkbox's box to the right , in check box attributes

android:button="@null" android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
like image 103
MSaudi Avatar answered Oct 20 '22 19:10

MSaudi