使用缩略图视图图像缩放显示大型png文件

时间:2015-02-04 20:46:10

标签: android performance

您好我已成功编写我的应用程序,以便从拇指视图显示大型png文件。单击拇指视图时,图像会放大到全屏。我遇到的问题是由于内存不足,应用程序运行速度非常慢。所以我试图通过使用“notifyDrawable”来节省内存,但是我在这方面是一个noobie而且我可能以错误的方式解决了这个问题。我想知道是否有人可以建议更好的方法来节省内存和一种让我的应用程序运行更顺畅的方法。这是我用过的代码:

final View thumb1View = findViewById(R.id.thumb_button_1);
    thumb1View.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            zoomImageFromThumb(thumb1View, R.drawable.page1);
        }
        @Override
        public void setImageDrawable(Drawable drawable) {

            final Drawable previousDrawable = getDrawable();
            super.zoomImageFromThumb(drawable);
            notifyDrawable(drawable, true);
            notifyDrawable(previousDrawable, false);
        }

        private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
            if (drawable instanceof English_Infants) {
                // The drawable is a CountingBitmapDrawable, so notify it
                ((English_Infants) drawable).setIsDisplayed(isDisplayed);
            } else if (drawable instanceof LayerDrawable) {
                // The drawable is a LayerDrawable, so recurse on each layer
                LayerDrawable layerDrawable = (LayerDrawable) drawable;
                for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
                    notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
                }
            }
        }


    });

0 个答案:

没有答案