Align text left, checkbox right

前端 未结 13 2276
孤街浪徒
孤街浪徒 2020-12-29 18:28

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 TextV

相关标签:
13条回答
  • 2020-12-29 18:46

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

    android:button="@null"
    android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
    
    0 讨论(0)
  • 2020-12-29 18:49

    Just set the switch: Layout Parameters -> Width to "match_parent"

    originally it's "wrap_content"

    0 讨论(0)
  • 2020-12-29 18:50

    My solution in this case is to use:

    <CheckBox
    ...
        android:button="@null"
        android:drawableRight="@drawable/my_check"
    ...
    />
    

    where my_radio could be for example you custom selector! Example of selector could be:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_checked="true" android:drawable="@drawable/check_checked" />
        <item android:state_checked="false" android:drawable="@drawable/check_unchecked" />
    </selector>
    
    0 讨论(0)
  • 2020-12-29 18:56

    You can achieve this by adding layoutDirection to "rtl"

    <CheckBox
                android:id="@+id/checkbox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right|center"
                android:layoutDirection="rtl"
                android:text="@string/declare_info_correct" />
    
    0 讨论(0)
  • 2020-12-29 18:57

    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.

    0 讨论(0)
  • 2020-12-29 18:58

    At the basis of Oibaf it's or MSaudi's solution

    android:button="@null"
    android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
    

    to add

    android:paddingLeft="0dp"
    

    to avoid the empty space at the checkbox left side in some device. The source link:

    How to show android checkbox at right side?

    answered by zeusboy.

    0 讨论(0)
提交回复
热议问题