Adjust custom checkMark position within CheckedTextView
Asked Answered
S

2

5

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.

Suburban answered 28/4, 2014 at 5:51 Comment(0)
I
9

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" />
Innerve answered 28/4, 2014 at 6:4 Comment(1)
Thank you, Dhwanik. center_vertical is exactly what I needed.Suburban
R
1

Maybe add "center_vertical".

android:gravity="center_vertical"

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

Refract answered 28/4, 2014 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.