How to show imageView full screen on imageView click?

后端 未结 10 601
暖寄归人
暖寄归人 2020-12-02 08:41

I am getting images from url and showing it on the imageView. This functionality is working properly. But I want that when I click on that image, then it must be full screen

相关标签:
10条回答
  • 2020-12-02 09:03

    You can use ImageView below two properties to show image based on your requirement :

    1. android:adjustViewBounds : Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

    2. android:scaleType :Controls how the image should be resized or moved to match the size of this ImageView

      <ImageView
          android:id="@+id/imageView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:adjustViewBounds="true"
          android:src="@drawable/ic_launcher"/>
      

    Above two properties can be use either xml or java code.

    As you need to decide at run time need to show image into full screen or not so will apply above two properties at java code as below :

    public class MainActivity extends Activity {
    
        ImageView imageView;
    
        boolean isImageFitToScreen;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            imageView = (ImageView) findViewById(R.id.imageView);
    
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(isImageFitToScreen) {
                        isImageFitToScreen=false;
                        imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                        imageView.setAdjustViewBounds(true);
                    }else{
                        isImageFitToScreen=true;
                        imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
                        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    }
                }
            });
    
        }
    }
    
    0 讨论(0)
  • 2020-12-02 09:07

    use following property of ImageView for full size of image

     android:scaleType="fitXY"
    

    ex :

          <ImageView
            android:id="@+id/tVHeader2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:gravity="center"
            android:src="@drawable/done_sunheading" />
    

    1)Switch on other activity when click on image.

    2)pass url in intent

    3)Take imageview on that Activity and set above property of imageview

    4)Get the url from intent and set that image.

    but using this your image may be starched if it will of small size.

    0 讨论(0)
  • 2020-12-02 09:07

    It's easy to achieve this is to just use an Intent like this: (I put the method in a custom class that takes in an Activity as a parameter so it can be called from any Fragment or Activity)

        public class UIutils {
    
    private Activity mActivity;
    
        public UIutils(Activity activity){
            mActivity = activity;
        }
    
    public void showPhoto(Uri photoUri){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(photoUri, "image/*");
            mActivity.startActivity(intent);
        }
    }
    

    Then to use it just do this:

    imageView.setOnClickListener(v1 -> new UIutils(getActivity()).showPhoto(Uri.parse(imageURI)));
    

    I use this with an Image URL but it can be used with stored files as well. If you are accessing images form the phones memory you should use a content provider.

    0 讨论(0)
  • 2020-12-02 09:13

    Yes I got the trick.

    public void onClick(View v) {
    
                if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ){
                    imgDisplay.setSystemUiVisibility( View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
    
                }
                else if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
                    imgDisplay.setSystemUiVisibility( View.STATUS_BAR_HIDDEN );
                else{}
    
        }
    

    But it didn't solve my problem completely. I want to hide the horizontal scrollview too, which is in front of the imageView (below), which can't be hidden in this.

    0 讨论(0)
提交回复
热议问题