【问题标题】:How to change button's size in checkbox如何更改复选框中的按钮大小
【发布时间】:2016-08-07 14:00:49
【问题描述】:

我尝试使用 png 文件更改 Checkbox 中的 Button,但图像太大,导致 Button 太大。

我想将 Button 的大小更改为 20dp。 然后我在CheckBox中设置了layout_width和layout_height,但是并没有解决问题。

你能教我如何改变尺寸吗?

<CheckBox
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:text="New CheckBox" 
    android:layout_margin="5dp"
    android:button="@drawable/my_check_box"
    android:layout_weight="1" />

my_check_box.xml

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

【问题讨论】:

  • 请注意,按钮不会像图片那样缩放。

标签: android button checkbox size


【解决方案1】:

你需要为它设置相关的drawable

<CheckBox 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:text="new checkbox" 
android:background="@drawable/my_checkbox_background"
android:button="@drawable/my_checkbox" />

这个链接有很好的例子 Custom Checkbox

【讨论】:

    猜你喜欢
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多