android


Android Custom Checkbox selector issue


I have to customize a checkbox to show 2 different state while checked, i am using the following 2 images :
My custom selector is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/favourite_normal" android:state_checked="false"/>
<item android:drawable="#drawable/favourite_choose" android:state_checked="true"/>
<item android:drawable="#drawable/favourite_normal"/>
But thing is i am not getting proper result as in the image does not fills my checkbox view properly if i change the height and width of the checkbox which i have to do to adjust. The result i am getting like this:
The complete layout is given below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="74dp"
android:background="#drawable/bottom_bav_btn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:id="#+id/linearLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/jokeListViewBackButton"
android:src="#drawable/back_screen_button_normal"
android:layout_margin="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/linearLayout"
android:layout_toLeftOf="#+id/linearLayout2"
android:layout_toStartOf="#+id/linearLayout2"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/jokeTitleTextView"
android:gravity="center_vertical|center_horizontal"
android:textColor="#color/fontWhiteColor" />
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0/0"
android:id="#+id/jokeCountTxt"
android:gravity="center_vertical|center_horizontal"
android:textColor="#color/fontWhiteColor" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/linearLayout2"
android:gravity="center_vertical|center_horizontal">
<CheckBox
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/checkBox"
android:button="#drawable/custom_favourite_selector"
android:gravity="center_vertical|center_horizontal"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:weightSum="1"
android:background="#color/listViewBody"
android:layout_weight="0.71">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/scrollView" >
<com.gravityapps.framework.Utils.CustomTextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=""
android:id="#+id/jokeTextView"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textSize="25dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp" />
</ScrollView>
</LinearLayout>
<LinearLayout android:id="#+id/navbar"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/prevButtonLayout"
android:clickable="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView2"
android:background="#drawable/previous_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/randPrevButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView3"
android:background="#drawable/reverse_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/linearLayout5"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView4"
android:background="#drawable/copy_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/linearLayout6"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView7"
android:background="#drawable/share_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/randNextButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView5"
android:background="#drawable/forward_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/nextButtonLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView6"
android:background="#drawable/next_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am not sure why i am getting this result. Any help would be appreciated. Thanks
The size of Checkbox 40dp*40dp smaller than the image you defined in selector.
use wrap_content instead of static dimensions.
Depending on the previous answer, if you don't want your checkbox to be larger, than you will have to resize your images. I think these are your best options, either you wrap_content your checkbox width and height or you resize your image resources into smaller, ex. 40*40px

Related Links

How to get many data from EditText using UI programmatically
android zxing barcode scanning getting Bound mismatch
Android - Are there any ad networks with custom sized mobile ads?
ZXing Barcode Android library getting ClassNotFoundException
Spinner values outsized, not all visible, and no scroll bar
Mapview invalidate exception in listview
Android:non-constant field error
automatic scrollable scrollview with textview
Android: How to set culture values for application
One method for several buttons?
How adjust the drawable in seek bar
How to Change Visibility of an ImageButton within a PagerAdapter?
Trouble using sharedPreferences between two activities
Move Android bitmap/canvas away from the top left
Populate Android Gallery from image file paths?
How to determine if a home screen shortcut exists?

Categories

HOME
sonarqube
httparty
grok
fabricjs
design-patterns
polymer
jax-rs
serialization
camera
simulink
web-hosting
zip
bookmarks
jetty
android-json
computer-science
sendgrid-api-v3
dkim
capistrano3
intershop
soci
selinux
poedit
articulate-storyline
joptionpane
xunit
entity-relationship-model
livelink
kudu
paragraph
mailkit
hunspell
pdw-file-browser
yowsup
magento-1.9.2.4
apic
health-monitoring
proget
openrasta
jquery-ui-draggable
geotiff
carrot2
flyout
vcloud-director-rest-api
slackware
ziparchive
parfor
iotivity
model-associations
jtwig
google-query-language
nss
ellucian-scribe
fink
pushbots
dock
sony-lifelog-api
linked-tables
diff3
mmwormhole
document-repository
machine-instruction
genymotion-call
raygun
ss7
malformedurlexception
memset
dot42
vsx
scriptaculous
mysql-error-1044
ie8-compatibility-mode
cffile
jquery-1.9
pclzip
video-codecs
wp7test
nokia-s40
qtconcurrent
jsr286
stress
catransform3d
google-floodlight
metaweblog
jqueryform
eclipse-marketplace
web-garden
opml
blender-2.49
request-headers
cuda.net
perl5.12
fdf
product-management
movieplayer

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App