Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust custom checkMark position within CheckedTextView

I have a ListView whereby each row contains a CheckedTextView. I am using a custom checkMark attribute, which uses a drawable:

<CheckedTextView
    android:id="@+id/body"
    android:gravity="left"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_below="@+id/date"
    android:textSize="18sp"
    android:checkMark="@drawable/checkbox_selector"
/>

The drawable checkbox_selector correctly handles the 'on' and 'off' selection as expected and is as follows:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_selected="true" android:state_pressed="true"
        android:drawable="@drawable/checkbox_on" > 
    </item>
    <item android:state_pressed="true" android:drawable="@drawable/checkbox_on" />
    <item android:state_checked="true" android:drawable="@drawable/checkbox_on"/>
    <item android:drawable="@drawable/checkbox_off" />
</selector>

Here is a screenshot of the current ListView layout:

ListView with checkMark visible

As you can see, the check box is top aligned. Is there any way to right-center it? Checking attributes of the selector resource, I can't find any relevant attributes to perform this.

Is there any way I could adjust its position? Thank you for your time.

like image 283
Heelara Avatar asked Dec 25 '22 10:12

Heelara


2 Answers

Try this.

<CheckedTextView
    android:id="@+id/body"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:checkMark="@drawable/checkbox_selector"
    android:checked="false"
    android:clickable="true"
    android:focusable="true"
    android:gravity="center_vertical"
    android:onClick="toggle"
    android:text="Some text here"
    android:textSize="18sp" />
like image 129
Dhwanik Gandhi Avatar answered Jan 08 '23 06:01

Dhwanik Gandhi


Maybe add "center_vertical".

android:gravity="center_vertical"

ref: http://developer.android.com/reference/android/widget/LinearLayout.html`

like image 42
Jerry Avatar answered Jan 08 '23 08:01

Jerry