I am trying to make a checkbox smaller. I have tried playing around with layout in XML and .width()/.height in Java. Neither does anything to change the size of it. I went to the tutorial that was recommended to other that asked this questions, but I did not understand what he did. Any suggestions?
Asked
Active
Viewed 1.9k times
4
-
Could you be a little bit more specific? How small do you want it? – Brian Jan 09 '12 at 01:53
-
The size of the checkbox to remember your username and password on Facebook – Aaron Jan 09 '12 at 01:59
-
possible duplicate of [Android: How to change CheckBox size?](http://stackoverflow.com/questions/2151241/android-how-to-change-checkbox-size) – Christoph Oct 26 '12 at 13:00
2 Answers
4
A simple way to do it, from API Level 11 is:
<CheckBox
...
android:scaleX="0.50"
android:scaleY="0.50"
...
/>

Lucas
- 1,224
- 1
- 14
- 21
-
1If your checkbox was overflowing out of the bounds before, this will simply reduce the size, won't take care of the overflow. – IcyFlame Jun 10 '16 at 09:02
-
1I came here looking for a simple way to enlarge the check area and this works very well – Joel Nov 11 '19 at 15:26
3
From another question here on SO:
You just need to set the related drawables and set them in the 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" />
The trick is on how to set the drawables. Here's a good tutorial about this.
EDIT: Just to make it a bit more clear, you will need these files to make the tutorial work:
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>
and btn_check_label_background.9.png, checkbox_off_background.png and checkbox_on_background.png from the tutorial page.
-
Tried to follow this tutorial, added the files that he added and then got lots or errors – Aaron Jan 09 '12 at 03:14
-
@Aaron: Could you be more specific about the errors that you received and the code in which you received them? – Robert Jan 09 '12 at 03:32
-
Sure I added the file my_check_background in drawables. More error poped up because in my_checkbox_background started referring to other files(my_checkbox_background_on). Every time I added another file more of the same type of errors popped up. – Aaron Jan 09 '12 at 04:15
-
@Aaron: See my edits to the answer above. I gave the code that I have in Eclipse that was also tested on my phone. – Robert Jan 09 '12 at 13:56