[英]Adjust custom checkMark position within CheckedTextView
我有一个ListView,每行包含一个CheckedTextView。 我正在使用自定义checkMark属性,该属性使用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"
/>
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布局的屏幕截图:
如您所见,复选框顶部对齐。 有没有办法让它正中心呢? 检查选择器资源的属性,我找不到任何相关的属性来执行此操作。
有什么方法可以调整它的位置吗? 感谢您的时间。
尝试这个。
<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" />
也许添加“center_vertical”。
android:gravity="center_vertical"
参考: http : //developer.android.com/ reference/android/ widget/ LinearLayout.html`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.