Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to scale Drawable with ScaleDrawable

Scaling with ScaleDrawable is not working for me.
The drawable is remained in the same size.

LayerDrawable layerDrawable = new LayerDrawable(layers);        
Drawable d = layerDrawable.getCurrent();
ScaleDrawable sd = new ScaleDrawable(d, 0, 0.01f, 0.01f); 
return sd.getDrawable();

What i need to do to fix it?
Thanks.

like image 553
Rami Avatar asked Jun 09 '12 11:06

Rami


2 Answers

You need to set the level:

LayerDrawable layerDrawable = new LayerDrawable(layers);        
Drawable d = layerDrawable.getCurrent();
ScaleDrawable sd = new ScaleDrawable(d, 0, 0.01f, 0.01f); 
sd.setLevel(8000);
return sd;

The level ranges from 0 to 10000: at 10000 it is full size, at 0 it does not appear at all.

like image 90
Femi Avatar answered Oct 02 '22 12:10

Femi


If you check the reference for ScaleDrawable, you will see that the getDrawable method returns the base drawable. That is, it returns d in your case. You should just return sd as it is already a Drawable.

like image 40
K-ballo Avatar answered Oct 02 '22 13:10

K-ballo