繁体   English   中英

更改android中复选框的大小

[英]Changing the size of a checkbox in android

我想把一个复选框缩小。 我尝试过使用XML中的布局和Java中的.width()/。height。 也没有任何改变它的大小。 我去了推荐给其他提出这个问题的教程,但我不明白他做了什么。 有什么建议?

从API Level 11开始,一个简单的方法是:

<CheckBox
...
android:scaleX="0.50"
android:scaleY="0.50"
...
/>

来自SO的另一个问题

您只需设置相关的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" />

诀窍是如何设置drawables。 这是一个很好的教程

编辑:只是为了使它更清楚,你将需要这些文件来使教程工作:

CheckBoxTestActivity.java:

import android.app.Activity;
import android.os.Bundle;

public class CheckBoxTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Checked CheckBox" 
        android:checked="true"/>

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Unchecked CheckBox" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/checkbox_background"
        android:button="@drawable/checkbox"
        android:text="New Checked CheckBox" 
        android:checked="true"/>

    <CheckBox
        android:id="@+id/checkBox4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/checkbox_background"
        android:button="@drawable/checkbox"
        android:text="New Unchecked CheckBox" />

</LinearLayout>

checkbox.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_off_background"/>

    <item 
        android:state_checked="true"
        android:drawable="@drawable/checkbox_on_background"/>

</selector>

checkbox_background.xml:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item 
        android:drawable="@drawable/btn_check_label_background" />   

</selector>

和教程页面中的btn_check_label_background.9.png,checkbox_off_background.png和checkbox_on_background.png。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM