android - Custom CheckBox image gets cut off -


checkbox

as can see in image above. there 3 views on screenshot.
- first item checkbox text , having state off.
- second item checkbox without text , having state on.
- last item imageview src pointing drawable image.

the checkboxes customized using android:button.

small checkbox

as tried using smaller images, of checkbox left-aligned.

comparing these 2 images tell me default size of checkbox seems fixed size until text attribute large enough require extending.

there nothing special in file well. see following.

custom_cb.xml

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

layout.xml

<?xml version="1.0" encoding="utf-8"?>  <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"               android:layout_width="match_parent"               android:layout_height="match_parent">     <checkbox android:id="@+id/cbfalse"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:button="@drawable/custom_cb"               android:text="" />     <checkbox android:id="@+id/cbtrue"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:button="@drawable/custom_cb"               android:focusable="false"               android:checked="true"               android:layout_torightof="@id/cbfalse" />     <imageview android:id="@+id/imvtrue"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:src="@drawable/creditcard"               android:layout_torightof="@id/cbtrue" /> </relativelayout> 

is there anyway can use bigger image checkbox while keeping size wrap_content? if set checkbox layout_width actual pixel or dp display full image mean have manually check size every time change.

today had same problem (my custom image cutted on left side). fixed putting:

android:button="@null" android:background="@drawable/my_custom_checkbox_state.xml" 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -