Android Image Dialog/Popup

后端 未结 7 779
臣服心动
臣服心动 2020-12-12 14:08

Is it possible to have just an image popup/come-up in an Android application? It\'s similar to an overriding the normal view of an AlertDialog so that it contains just an im

7条回答
  •  眼角桃花
    2020-12-12 14:26

    Try the following:
    It has image zoom_in/zoom_out as well.

    Step 1:
    Add compile 'com.github.chrisbanes.photoview:library:1.2.4' to your build.gradle
    Step 2:
    Add the following xml


    custom_fullimage_dialoge.xml

    
        
        
    
        
        
    
    

    Step 3:

    private void loadPhoto(ImageView imageView, int width, int height) {
    
        final Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        //dialog.setContentView(R.layout.custom_fullimage_dialog);
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.custom_fullimage_dialog,
                (ViewGroup) findViewById(R.id.layout_root));
        ImageView image = (ImageView) layout.findViewById(R.id.fullimage);
        image.setImageDrawable(imageView.getDrawable());
        image.getLayoutParams().height = height;
        image.getLayoutParams().width = width;
        mAttacher = new PhotoViewAttacher(image);
        image.requestLayout();
        dialog.setContentView(layout);
        dialog.show();
    
    }
    

    Step 4:

    user_Image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Display display = getWindowManager().getDefaultDisplay();
            int width = display.getWidth();
            int height = display.getHeight();
            loadPhoto(user_Image,width,height);
        }
    });
    

提交回复
热议问题