【问题标题】:how to scale image and set background efficiently android如何有效地缩放图像和设置背景android
【发布时间】:2015-07-12 14:08:16
【问题描述】:

我想开始一个新项目,我想知道如何非常有效地为我的活动(布局)设置背景

这是我在 onCreate 方法中尝试的:

String imageUri = "drawable://" + R.drawable.perfectwall;
        int width = getWindowManager().getDefaultDisplay().getWidth();
        int height = getWindowManager().getDefaultDisplay().getHeight();
        Bitmap reqBitmap = loadBitmap(imageUri, width, height);
        Drawable drawable = new BitmapDrawable(this.getResources(), reqBitmap);
        r.setBackground(drawable);

我还有一个问题,为什么这不起作用...当我在模拟器上启动应用程序时,尽管内存越来越高,但它并没有改变背景......最多使用了 12MB.. 它只是一个白屏好像我没有设置背景

非常感谢!

【问题讨论】:

    标签: android memory bitmap scale android-relativelayout


    【解决方案1】:

    考虑使用 Picasso 和 Universal Image Loader 等库。它们专为您想要的东西而构建:有效地缩放大图像并将其加载到图像视图中。我过去都使用过,并为它们提供担保。

    【讨论】:

    • 如果我不想只看图像?例如屏幕布局或图像按钮
    • 它给了我这个错误:Error:Execution failed for task ':app:mergeDebugResources'. > Crunching Cruncher background.png failed, see logs
    • @xyz 所以只需使用r.setBackgroundResource(R.drawable.perfectwall)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多