【问题标题】:How to resize image of checkbox in android?如何在android中调整复选框的图像?
【发布时间】:2015-11-18 18:18:29
【问题描述】:

我正在为 CheckBox 小部件添加图像(而不是使用选择器在 .xml 文件中单击和未单击的默认图像)它正在被添加,但图像无法调整为较小的图像并保留原尺寸。

如何减小图片尺寸?

我用来创建 CheckBox 的代码是

    <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:button="@drawable/check_box"
            android:drawablePadding="20dp"
            android:text="check box text"
            android:textColor="@color/labelColor" />

【问题讨论】:

    标签: android xml android-layout checkbox


    【解决方案1】:

    android:button字段设置为null,并将复选框设置为复选框的android:background字段

        <CheckBox    
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:button="@null"
                android:drawablePadding="20dp"
                android:text="check box text"
                android:background="@drawable/check_box" />
    

    【讨论】:

    • 这不是很有帮助吗? @allDroid
    • 为我工作@Amit Vaghela 谢谢? 该图标仅部分显示,此更改图标大小相应减小。
    【解决方案2】:

    android:button 字段设置为 null 并将复选框状态设置为复选框的 android:background 字段。

    您的代码将变为:

    <CheckBox
    android:id="@+id/cb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:button="@null"
    android:background="@drawable/check_box"
    android:drawablePadding="20dp"
    android:text="check box text"
    android:textColor="@color/labelColor" />
    

    【讨论】:

      【解决方案3】:

      @berry:请设置android:button="@null" 并将其设置在您的android:background 中。

       android:button="@null"
       android:background="@drawable/check_box.xml"
      

      当布局宽度和高度设置为 wrap_content 时,CheckBox 不考虑 android:button 可绘制按钮的大小。所以使用 android:background

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-11
        • 1970-01-01
        • 2017-12-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多