Android ImageView图片放大到全屏显示

1.点击图片放大到全屏显示

private void initImageView() {
    final WindowManager windowManager = getWindowManager();
    final RelativeLayout relativeLayout = new RelativeLayout(this);
    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
    getScreenWidthAndHeight();
    layoutParams.width = mScreenWidth;
    layoutParams.height = mScreenHeight;
    //FLAG_LAYOUT_IN_SCREEN
    layoutParams.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
    layoutParams.format = PixelFormat.RGBA_8888;//让背景透明,放大过程可以看到当前界面
    layoutParams.verticalMargin = 0;
    windowManager.addView(relativeLayout,layoutParams);

    final PhotoView animationIV = new PhotoView(getContext());
    animationIV.setScaleType(ImageView.ScaleType.FIT_CENTER);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
    relativeLayout.addView(animationIV,params);
    relativeLayout.setFocusableInTouchMode(true);
    Picasso.with(getContext()).load(imageId).into(animationIV);

    animationIV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            windowManager.removeView(relativeLayout);
        }
    });

    relativeLayout.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (null != windowManager && null != relativeLayout) {
                    windowManager.removeView(relativeLayout);
                }
                return true;
            }
            return false;
        }
    });
}

2.PhotoView是继承ImageView,实现是对图片放大后可以局部的拉伸放大,双击放大

Demo下载地址:https://download.csdn.net/download/qq_39735504/10300619

你可能感兴趣的:(Android ImageView图片放大到全屏显示)