コード例 #1
0
 @Override
 public void onAnimationEnd(Animation animation) {
   ImageUtil.recycle(layerView);
 }
コード例 #2
0
ファイル: PageView2.java プロジェクト: litingwen624/magazine
 /**
  * 上下滑动时资源的回收和加载,加载上中下3屏的图片资源,其余释放
  *
  * @param Y
  * @param childCount
  */
 protected void loadResource(int Y, int childCount) {
   int minY = Y - UNIT;
   int maxY = Y + UNIT * 2;
   for (int i = 0; i < childCount; i++) {
     View childView = getFrameLayout().getChildAt(i);
     if (childView instanceof FirstGroupView) {
       FirstGroupView firstGroupView = (FirstGroupView) childView;
       int childCount2 = firstGroupView.getChildCount();
       for (int j = 0; j < childCount2; j++) {
         View view = firstGroupView.getChildAt(j);
         if (view instanceof PictureView) {
           PictureView pictureView = (PictureView) view;
           LayoutParams params = (LayoutParams) pictureView.getLayoutParams();
           if (minY <= params.topMargin && params.topMargin < maxY) { // 加载FirstGroupView资源
             if (!pictureView.isLoad()) {
               Picture picture = pictureView.getPicture();
               if (picture != null) {
                 String resource = picture.getResource();
                 String imgPath =
                     AppConfigUtil.getAppResourceImage(AppConfigUtil.MAGAZINE_ID, resource);
                 Bitmap bitmap = ImageUtil.loadImage(imgPath);
                 pictureView.setImageBitmap(bitmap);
                 pictureView.setScaleType(ScaleType.FIT_XY);
               }
             }
           } else { // 释放FirstGroupView资源,如果只有一张底图,将不释放资源
             Group group = pictureView.getGroup();
             List<Picture> pictures = group.getPictures();
             if (pictures.size() >= 2) {
               ImageUtil.recycle(pictureView);
             }
           }
         }
       }
     } else if (childView instanceof GroupView2) {
       GroupView2 groupView = (GroupView2) childView;
       LayoutParams params = (LayoutParams) groupView.getLayoutParams();
       if (minY <= params.topMargin && params.topMargin < maxY) { // 加载GroupView资源
         FrameLayout frameLayout = groupView.getFrameLayout();
         int childCount2 = frameLayout.getChildCount();
         for (int j = 0; j < childCount2; j++) {
           View view = frameLayout.getChildAt(j);
           if (view instanceof PictureView) {
             PictureView pictureView = (PictureView) view;
             if (!pictureView.isLoad()) {
               Picture picture = pictureView.getPicture();
               if (picture != null) {
                 String resource = picture.getResource();
                 if (resource != null) {
                   String imgPath =
                       AppConfigUtil.getAppResourceImage(AppConfigUtil.MAGAZINE_ID, resource);
                   Bitmap bitmap = ImageUtil.loadImage(imgPath);
                   pictureView.setImageBitmap(bitmap);
                   pictureView.setScaleType(ScaleType.FIT_XY);
                 }
               }
             }
           }
         }
       } else { // 释放GroupView资源
         FrameLayout frameLayout = groupView.getFrameLayout();
         int childCount2 = frameLayout.getChildCount();
         for (int j = 0; j < childCount2; j++) {
           View view = frameLayout.getChildAt(j);
           if (view instanceof PictureView) {
             PictureView pictureView = (PictureView) view;
             ImageUtil.recycle(pictureView);
           }
         }
       }
     } else if (childView instanceof HorizontalGroupView) {
       HorizontalGroupView hGroupView = (HorizontalGroupView) childView;
       LayoutParams hparams = (LayoutParams) hGroupView.getLayoutParams();
       if (minY <= hparams.topMargin && hparams.topMargin < maxY) { // 加载GroupView资源
         FrameLayout frameLayout = hGroupView.getFrameLayout();
         int childCount2 = frameLayout.getChildCount();
         for (int j = 0; j < childCount2; j++) {
           View view = frameLayout.getChildAt(j);
           if (view instanceof PictureView) {
             PictureView pictureView = (PictureView) view;
             if (!pictureView.isLoad()) {
               Picture picture = pictureView.getPicture();
               if (picture != null) {
                 String resource = picture.getResource();
                 if (resource != null) {
                   String imgPath =
                       AppConfigUtil.getAppResourceImage(AppConfigUtil.MAGAZINE_ID, resource);
                   Bitmap bitmap = ImageUtil.loadImage(imgPath);
                   pictureView.setImageBitmap(bitmap);
                   pictureView.setScaleType(ScaleType.FIT_XY);
                 }
               }
             }
           }
         }
       }
     }
   }
 }