其他分享
首页 > 其他分享> > Android:如何在底部对齐CheckBox文本?

Android:如何在底部对齐CheckBox文本?

作者:互联网

基本上我想要的是一个带有图标和图标下方文本的复选框,如下所示:

 -------------------
|   CheckBox Icon   |
|                   |
|   CheckBox Text   |
|                   |
 -------------------

默认情况下,图标位于左侧,文本位于右侧,两者位于同一级别.在我正在使用的布局下面:

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Switch state"
    android:button="@drawable/my_custom_selector" />

有关如何实现将图标放在顶部以及图标下方的文本的任何想法?提前致谢 :)

解决方法:

带有已检查和未选中的drawables的CheckedTextView状态列表:

<CheckedTextView
    android:drawableTop="@drawable/checkmark"
    android:checked="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Checked text"/>

@绘制/对勾

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/unchecked" android:state_checked="false"></item>
<item android:drawable="@drawable/checked"></item></selector>

(checkmark.xml已简化).

标签:android,android-layout,android-view,android-checkbox
来源: https://codeday.me/bug/20190716/1476760.html