Android: Slow performance using a big image in ImageView

前端 未结 2 929
遇见更好的自我
遇见更好的自我 2021-01-05 08:19

I have an Activity where I have a background image in an ImageView, and nine transparent buttons on top of the image.

http://i.stack.imgur.com/GGQqd.png

2条回答
  •  走了就别回头了
    2021-01-05 09:02

    You can use Dave Morissey's Subsampling Scale Image View as a drop in replacement of the standard image view.

    XML layout:

    
                
    

    Set image in code and disable touch:

    photo = (SubsamplingScaleImageView) view.findViewById(R.id.photo);
    photo.setOnTouchListener(new View.OnTouchListener() {
                                @Override
                                public boolean onTouch(View v, MotionEvent event) {
                                    return true;
                                }
                            });
    photo.setImage(ImageSource.uri(Uri.fromFile(new File("/somepath/file.png"))));
    

    build.gradle:

    compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'

提交回复
热议问题