android中的CheckBox改变背景图片显示大小

news/2025/2/26 5:32:03

androidStudio的xml文件设置布局时,对于checkBox选中后,展示大小不同的背景图片

1.首先需要一个选择器存放背景图片,设置选中和未选中状态

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_hair1_cheek" android:state_checked="true" />
    <item android:drawable="@drawable/ic_hair1" />
</selector>

2.在布局文件中设置对应的checkBox,如果对应选中的图片大小不一样的时候,使用一下布局方式可以展示出对应的大小;

 <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/cl_hair_color"
            app:layout_constraintLeft_toRightOf="@+id/iv_hair_color"
            app:layout_constraintBottom_toBottomOf="@id/iv_hair_color"
            app:layout_constraintTop_toBottomOf="@+id/tv_hair_color"
            android:layout_width="wrap_content"
            android:layout_height="65dp">

            <androidx.appcompat.widget.AppCompatCheckBox
                android:id="@+id/cb_hair1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:background="@null"
                android:button="@drawable/selector_hair1"
                android:clickable="false"
                android:layout_width="54dp"
                android:layout_height="54dp"/>

            <androidx.appcompat.widget.AppCompatCheckBox
                android:id="@+id/cb_hair2"
                app:layout_constraintLeft_toRightOf="@+id/cb_hair1"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:background="@null"
                android:button="@drawable/selector_hair2"
                android:clickable="false"
                android:layout_marginLeft="15dp"
                android:layout_width="54dp"
                android:layout_height="54dp"/>

            <androidx.appcompat.widget.AppCompatCheckBox
                android:id="@+id/cb_hair3"
                app:layout_constraintLeft_toRightOf="@+id/cb_hair2"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:background="@null"
                android:button="@drawable/selector_hair3"
                android:clickable="false"
                android:layout_marginLeft="15dp"
                android:layout_width="54dp"
                android:layout_height="54dp"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

主要实现时布局中的 

android:background="@null"
android:button="@drawable/selector_hair3"

如果将其反过来,则选中前后的图片大小都会保持不变

android:background="@drawable/selector_hair3"
android:button="@null"


http://www.niftyadmin.cn/n/5868056.html

相关文章

嵌入式硬件篇---数字电子技术中的逻辑运算

、 文章目录 前言一、基本逻辑运算1. 与运算&#xff08;AND&#xff09;符号真值表功能应用 2. 或运算&#xff08;OR&#xff09;符号真值表功能应用 3. 非运算&#xff08;NOT符号真值表功能应用 4. 异或运算&#xff08;XOR&#xff09;符号真值表功能应用 5. 同或运算&…

全星FMEA软件系统是一款高效、智能的失效模式及影响分析工具,广泛应用于汽车、电子、机械等行业

全星FMEA软件系统是一款高效、智能的失效模式及影响分析工具&#xff0c;广泛应用于汽车、电子、机械等行业。该系统基于2019版FMEA手册开发&#xff0c;严格遵循七步方法&#xff0c;能够全面识别潜在风险并提前制定应对措施。 全星FMEA软件系统功能特点 自动化分析&#xff…

ubuntu20.04 突破文件数限制

增加文件描述符的限制 每个网络连接都占用一个文件描述符。增加文件描述符的数量&#xff0c;可以让系统处理更多的并发连接。 1.1 临时修改文件描述符限制 首先&#xff0c;查看当前的文件描述符限制&#xff1a; ulimit -n然后&#xff0c;将文件描述符限制增大&#xff0c…

Kafka 消费者组内分区分配策略 以及 管理控制台方案

一、Kafka 消费者组内分区分配策略 Kafka 通过 partition.assignment.strategy 参数控制消费者组内的分区分配策略&#xff0c;以下是主要策略及特点&#xff1a; 1. RangeAssignor&#xff08;默认策略&#xff09; partition.assignment.strategyorg.apache.kafka.clients…

9. grafana的bar gauge使用

1. 选择bar gauge 2. 填充数据源 3. 修改 Display 3. 在Field中的设置

Oracle 数据变化量查询

1. DBA_HIST_SEG_STAT可以看出对象的使用趋势&#xff0c;构造如下SQL查询出每个时间段内数据库对象的增长量 select c.SNAP_ID,to_char(c.END_INTERVAL_TIME, yyyy-mm-dd) SNAP_TIME,a.OWNER,a.OBJECT_NAME,a.OBJECT_TYPE,b.DB_BLOCK_CHANGES_DELTAfrom dba_objects a,(selec…

将VsCode变得顺手好用(1

目录 设置中文 配置调试功能 提效和增强相关插件 主题和图标相关插件 设置中文 打开【拓展】 输入【Chinese】 下载完成后重启Vs即可变为中文 配置调试功能 在随便一个位置新建一个文件夹&#xff0c;用于放置调试文件以及你未来写的代码&#xff0c;随便命名但切记不可用中…

Go基于协程池的延迟任务调度器

原理 通过用一个goroutine以及堆来存储要待调度的延迟任务&#xff0c;当达到调度时间后&#xff0c;将其添加到协程池中去执行。 主要是使用了chan、Mutex、atomic及ants协程池来实现。 用途 主要是用于高并发及大量定时任务要处理的情况&#xff0c;如果使用Go协程来实现每…