我正在为进度对话框(pbarDialog
)设置可绘制对象,但是我的问题是我想每次都调整可绘制对象的大小,但无法弄清楚该怎么做。
这是一些代码:
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
// some more code
case UPDATE_PBAR:
pbarDialog.setIcon(mAppIcon);
pbarDialog.setMessage(mPbarMsg);
pbarDialog.incrementProgressBy(mIncrement+1);
break;
}
}
};
pbarDialog.show();
Thread myThread = new Thread(new Runnable() {
public void run() {
// some code
for (int i = 0; i < mApps.size(); i++) {
mAppIcon = mAdapter.getIcons().get(mApps.get(i).getPackageName());
// need to resize drawable here
progressHandler.sendEmptyMessage(UPDATE_PBAR);
}
handler.sendEmptyMessage(DISMISS_PBAR);
}
});
myThread.start();
最佳答案
以下为我工作:
private Drawable resize(Drawable image) {
Bitmap b = ((BitmapDrawable)image).getBitmap();
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, 50, 50, false);
return new BitmapDrawable(getResources(), bitmapResized);
}
关于android - 在Android中调整Drawable的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7021578/