How to align the checkboxes in the checkedtextView in android

雨燕双飞 提交于 2019-12-14 03:16:58

问题


I have a scrollView containing a form composed by multiple CheckedTextView, my problem is that the check boxes of these ones are not in the same level, they are at this end of every text, what i want is to have them aligned so it looks good as a form. How to do that? i've been searching for hours but nothing yet.

how i have them :

blablablablablabla x

blablablablablablablablablablablabla x

blabla x

how i want them :

blablablablablabla                   x

blablablablablablablablablablablabla x

blabla                               x

回答1:


This may solve the purpose

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
         android:orientation="vertical">

        <CheckedTextView
            android:id="@+id/my_checkedtextview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:checked="true"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:hint="My text one" />

        <CheckedTextView
            android:id="@+id/my_checkedtextview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:checked="true"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:hint="Trying a larger text " />

        <CheckedTextView
            android:id="@+id/my_checkedtextview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:checked="true"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:hint="Checked" />

        <CheckedTextView
            android:id="@+id/my_checkedtextview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:checked="true"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:hint="text with some more text" />

        <CheckedTextView
            android:id="@+id/my_checkedtextview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:checked="true"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:hint="Checked" />

        <CheckedTextView
            android:id="@+id/my_checkedtextview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:checked="true"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:hint="Checked" />
    </LinearLayout>

</ScrollView>

Also attached the output.




回答2:


As a solution, I used single checkboxes and textviews



来源:https://stackoverflow.com/questions/19228542/how-to-align-the-checkboxes-in-the-checkedtextview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!