-1
我已经看了很多关于如何改变drawable的大小的线程,但他们都没有工作。ScaleDrawable似乎没有工作
位图抛出类抛出异常,甚至设置ScaleDrawable的级别不起作用。
怎么了?我不是在寻找一个xml解决方案,因为我想根据屏幕的大小来根据其他项目的大小来调整大小。
谢谢。
//set seekbar thumb to height of bar
Drawable thumb = mSeekBarSpeed.getThumb();
thumb = new ScaleDrawable(thumb, 0, thumb.getIntrinsicWidth(), mSeekBarSpeed.getHeight());
thumb.setLevel(10000);
thumb.setBounds(0, 0, thumb.getIntrinsicWidth(), thumb.getIntrinsicHeight());
// Bitmap thumbBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.seekbar_thumb);
// Bitmap scaled = Bitmap.createScaledBitmap(thumbBitmap, thumb.getIntrinsicWidth(), mSeekBarSpeed.getHeight(), true);
////
//// Bitmap thumb = Bitmap.createBitmap(50,50, Bitmap.Config.ARGB_8888);
//// Canvas canvas=new Canvas(thumb);
//// canvas.drawBitmap(bitmap,new Rect(0,0,bitmap.getWidth(),bitmap.getHeight()),
//// new Rect(0,0,thumb.getWidth(),thumb.getHeight()),null);
//// Drawable drawable = new BitmapDrawable(getResources(),thumb);
//// setThumb(drawable);
//
// //Drawable thumb = mSeekBarSpeed.getThumb();
//// thumb.setBounds(0,0, thumb.getIntrinsicWidth(), mSeekBarSpeed.getHeight());
//// Bitmap orig = ((BitmapDrawable)thumb).getBitmap();
//// Bitmap scaled = Bitmap.createScaledBitmap(orig, thumb.getIntrinsicWidth(), mSeekBarSpeed.getHeight(), true);
// Drawable newThumb = new BitmapDrawable(getResources(), scaled);
// newThumb.setBounds(0,0,newThumb.getIntrinsicWidth(),newThumb.getIntrinsicHeight());
mSeekBarSpeed.setThumb(thumb);