android - Scaling selector drawable -


i have drawable used in selector. image/drawable star , selector used checkbox , should represent favorite-button.

<?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/star" />     <item android:state_checked="true" android:drawable="@drawable/star_faved" /> </selector> 

the images 256x256px big , dont scale when used checkbox. tried use 9patch, couldnt work.

    <checkbox android:layout_width="20dp"               android:layout_height="20dp"               android:text="read"               android:button="@drawable/favorite_checkbox"               android:focusable="false"/> 

what standard way approach this?

256x256 px seems big enough xxxhdpi resource.
so, imagine made @ 640 dpi.

a 9 patch won't in case, since stretch graphics.

make sure have @ least xxxhdpi resource @ xxxhdpi (normalized) resolution of 640 dpi

i used icon iconmonstr.com... pictures icon sites done @ low quality (good enough pcs) of 72 dpi (usually / 96 dpi - rarely, better quality).

imagine lowest android dpi (for ldpi screen) 120 dpi, double...
if want quality, dpi use are:

  • 120 ldpi, scale factor = 0.75
  • 160 mdpi, scale factor = 1.0
  • 240 hdpi, scale factor = 1.5
  • 320 xhdpi, scale factor = 2.0
  • 480 xxhdpi, scale factor = 3.0
  • 640 xxxhdpi, scale factor = 4.0

normally, scaling down work perfectly.
so, having xxxhdpi or xhdpi resource scaled.

now, have enhance quality.
72dpi => 640dpi - leave same size (bring 640 dpi, automatically scale bigger sizes, reduce size 256*256 again, leaving dpi set 640).

save these images /res/drawable-xxxhdpi folder

[edit]

the correct picture sizes checkbox should 48*4 (192) px full asset (meaning image + padding, 16px per side, transparent) , 40*4 (160) px graphics (the "optical square"), xxxhdpi resolution.

[edit 2]

48, @ mdpi resolution (160 dpi, scale factor = 1.0)
4.0 being scale factor xxxhdpi resolution

since images become big (in weight), recommend using optipng, reduce overall byte count without losing quality.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -