【问题标题】:Adjust custom checkMark position within CheckedTextView调整 CheckedTextView 中的自定义 checkMark 位置
【发布时间】:2014-04-28 05:51:31
【问题描述】:

我有一个 ListView,其中每一行都包含一个 CheckedTextView。我正在使用自定义 checkMark 属性,该属性使用可绘制对象:

<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"
/>

drawable checkbox_selector按预期正确处理'on'和'off'选择,如下:

<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>

这是当前 ListView 布局的截图:

如您所见,复选框顶部对齐。有什么办法可以将其居中吗?检查选择器资源的属性,我找不到任何相关属性来执行此操作。

有什么办法可以调整它的位置吗?感谢您的宝贵时间。

【问题讨论】:

    标签: android listview checkedtextview checkmark


    【解决方案1】:

    试试这个。

    <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" />
    

    【讨论】:

    • 谢谢你,Dhwanik。 center_vertical 正是我所需要的。
    • 欢迎您 :) 如果您觉得这个答案有帮助,您可以接受
    【解决方案2】:

    也许添加“center_vertical”。

    android:gravity="center_vertical"
    

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

    【讨论】:

    • 谢谢你,杰瑞。这有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多