Resize checkbox in android

I am trying to make the checkbox smaller. I tried playing with layout in XML and .width () /. Height in Java. Nothing will change its size. I went to a textbook recommended by others who asked these questions, but I did not understand what he had done. Any suggestions?

+4
source share
2 answers

From another question here on SO:

You just need to install the relevant drawings 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 how to install the drawings. Here is a good lesson about this .

EDIT: to make this more understandable, you will need these files to make the tutorial:

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 training page.

+3
source

An easy way to do this, starting at API level 11:

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

Source: https://habr.com/ru/post/1389976/


All Articles