【发布时间】:2012-02-05 16:09:12
【问题描述】:
我正在尝试使复选框更小。我尝试过使用 XML 中的布局和 Java 中的 .width()/.height。也没有任何改变它的大小。我去了向其他提出这个问题的人推荐的教程,但我不明白他做了什么。有什么建议吗?
【问题讨论】:
-
你能说得更具体一点吗?你想要多小?
-
用于记住您在 Facebook 上的用户名和密码的复选框的大小
我正在尝试使复选框更小。我尝试过使用 XML 中的布局和 Java 中的 .width()/.height。也没有任何改变它的大小。我去了向其他提出这个问题的人推荐的教程,但我不明白他做了什么。有什么建议吗?
【问题讨论】:
从 API 级别 11 开始,一个简单的方法是:
<CheckBox
...
android:scaleX="0.50"
android:scaleY="0.50"
...
/>
【讨论】:
来自另一个question,这里是:
你只需要设置相关的drawable并在checkbox里设置:
<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" />
诀窍在于如何设置可绘制对象。 Here's a good tutorial about this.
编辑:为了更清楚一点,您将需要这些文件来完成教程:
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。
【讨论】: