调整绘制对象在Android中 [英] Resize Drawable in Android

查看:139
本文介绍了调整绘制对象在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置的可绘制的进度对话框( 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);
}
 

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);
}

这篇关于调整绘制对象在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆