PhotoView图片的放大和缩小的用法

点击图片使图片放大和缩小 的主要源码如下;

 //想让图片宽是屏幕的宽度
        //测量
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;//只测量
        float height = bitmap.getHeight();
        float width = bitmap.getWidth();
        //再拿到屏幕的宽
        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        float screenWidth = display.getWidth();
        //计算如果让照片是屏幕的宽,选要乘以多少?
        scale = screenWidth / width;
        if (scale == 0) {
            scale = 1;
        }
        //这个时候。只需让图片的宽是屏幕的宽,高乘以比例
        int displayHeight = (int) (height * scale);//要显示的高,这样避免失真
        //最终让图片按照宽是屏幕 高是等比例缩放的大小
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams((int) screenWidth, displayHeight);
        photoView.setLayoutParams(layoutParams);

PhotoViewAttacher attacher = new PhotoViewAttacher(photoView);
最后这句话最重要的


你可能感兴趣的:(PhotoView图片的放大和缩小的用法)