Как вы можете видеть на изображении выше. На этом скриншоте есть три вида.
- Первый элемент CheckBox
с текстом и с выключенным состоянием.
- Второй элемент CheckBox
без текста и состояния.
- Последний элемент ImageView
с src, указывающим на отображаемое изображение.
Элементы CheckBox были настроены с помощью android:button
.
Как я пытался использовать меньшие изображения, все флажки выровнены по левому краю.
Сравнение этих двух изображений говорит мне, что размер по умолчанию CheckBox
кажется фиксированным до определенного размера, пока текстовый атрибут не будет достаточно большим, чтобы требовать расширения.
В файле нет ничего особенного. См. Ниже.
custom_cb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/creditcard_selected" android:state_checked="true" />
<item android:drawable="@drawable/creditcard"/>
</selector>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox android:id="@+id/cbFalse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/custom_cb"
android:text="" />
<CheckBox android:id="@+id/cbTrue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/custom_cb"
android:focusable="false"
android:checked="true"
android:layout_toRightOf="@id/cbFalse" />
<ImageView android:id="@+id/imvTrue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/creditcard"
android:layout_toRightOf="@id/cbTrue" />
</RelativeLayout>
В любом случае я могу использовать большее изображение для CheckBox, сохраняя размер wrap_content
? Если я устанавливаю CheckBox layout_width
на фактический пиксель или dp, тогда он отображает полное изображение, но это означает, что я должен вручную проверять размер каждый раз, когда он изменяется.