由网友(简柠)分享简介:我设置的可绘制的进度对话框( pbarDialog ),但我的问题是,我希望每次调整的绘制,但无法弄清楚如何。下面是一些code:处理程序progressHandler =新的处理程序(){公共无效的handleMessage(信息MSG){开关(msg.what){//一些code案例UPDATE_PBAR:pbar...![Android全方位性能调优 避免过度渲染](https://p.xsw88.cn/allimgs/daicuo/20230903/5705.png)
我设置的可绘制的进度对话框( pbarDialog
),但我的问题是,我希望每次调整的绘制,但无法弄清楚如何。
下面是一些code:
处理程序progressHandler =新的处理程序(){
公共无效的handleMessage(信息MSG){
开关(msg.what){
//一些code
案例UPDATE_PBAR:
pbarDialog.setIcon(mAppIcon);
pbarDialog.setMessage(mPbarMsg);
pbarDialog.incrementProgressBy(mIncrement + 1);
打破;
}
}
};
pbarDialog.show();
螺纹myThread =新主题(新的Runnable(){
公共无效的run(){
//一些code
的for(int i = 0; I< mApps.size();我++){
。mAppIcon = mAdapter.getIcons()得到(mApps.get(ⅰ).getPackageName());
//这里需要调整绘制
progressHandler.sendEmptyMessage(UPDATE_PBAR);
}
handler.sendEmptyMessage(DISMISS_PBAR);
}
});
myThread.start();
解决方案
对我下面的工作:
私人绘制对象调整大小(绘制的图像){
位图B =((BitmapDrawable)图像).getBitmap();
位图bitma presized = Bitmap.createScaledBitmap(B,50,50,FALSE);
返回新BitmapDrawable(getResources(),bitma presized);
}
![Android全方位性能调优 避免过度渲染](https://p.xsw88.cn/allimgs/daicuo/20230903/5705.png)
I am setting a drawable for a progress dialog (pbarDialog
) but my issue is I want to resize the drawable each time but can't figure out how.
Here is some code:
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();
解决方案
The following worked for me:
private Drawable resize(Drawable image) {
Bitmap b = ((BitmapDrawable)image).getBitmap();
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, 50, 50, false);
return new BitmapDrawable(getResources(), bitmapResized);
}
相关推荐
最新文章