1

I know there are lots of questions like these. However, they all seek to bring imageView on full screen after clicking.

I want to bring an imageView on Full Screen without clicking on it. In other words, when I click my bitmap, I should get a full-screen imageView. I tried a lot but could not achieve desired results.

So far, I have tried this thread's all possible solutions.

Moreover, I tried to use multiple scaling options.

I am self-learning android using a big nerd's ranch guide. I am attaching my code and images below

public View onCreateView(LayoutInflater inflater,
                             ViewGroup parent, Bundle savedInstanceState) {
        imageView=new ImageView(getActivity());
        String path= (String) getArguments().getSerializable(FILE_PATH_NAME);
        BitmapDrawable image = PictureUtils.getScaledDrawable(getActivity(), path);
        float rotation= rotateImage(getActivity(), path);
        Log.i("RotateImagee", "Rotate valuee: " + rotation);
        imageView.setRotation(rotation + 90);
        imageView.setImageDrawable(image);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        return imageView;
    }

Images: enter image description here

I want screen fully covered with this image with a proper scaling. Therefore, please show me an appropriate solution with proper scaling.

Community
  • 1
  • 1
WOW
  • 99
  • 1
  • 10
  • before "downvoting" please read the description carefully. I clearly distinguish my question from the rest out there! – WOW Jan 08 '16 at 13:21
  • Have you tried `imageView.setScaleType(ScaleType.FIT_XY); imageView.setAdjustViewBounds(true);`? Also, having a second call to `setScaleType()` makes the first one useless. – SqueezyMo Jan 08 '16 at 13:30
  • Thanks for replying! I tried all possible combinations of setScaleType() methods. However, I could not achieve the desired results. I also tried imageView.setAdjustViewBounds(true); but didn't get results. The image remains in this frame with different scalings. It does not go full screen – WOW Jan 08 '16 at 13:33
  • Show us your activity's layout (and how your fragment is nested in it). Also, it might help to turn on the "highlight layout borders" option in the developer settings of your device. – SqueezyMo Jan 08 '16 at 13:47

2 Answers2

2

You can use only one scaletype and CENTER_INSIDE overrides FIT_XY. Use only FIT_XY. Senconly when you create your ImageView you don't give it layoutparams(default is wrap_content), so you need to set layoutparams to match_parent. Without it imageView will change size to wrap_content and FIT_XY will not take affect.

Here is a link if you want to make activity full screen. you also need to remove ActionBar, Here.

Community
  • 1
  • 1
milad zahedi
  • 787
  • 6
  • 21
  • As mentioned above, I tried all possible combinations of attached thread. imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); I used this code. I did not get a full-screen view just a scaled one. I also called FIT_XY. However, I only got a proper scaled version that stays under that gray box! – WOW Jan 08 '16 at 13:37
  • I don't understand why it stays under this gray box. Moreover, what does this gray box represents. Is it my parent's layout? – WOW Jan 08 '16 at 13:39
  • What do you mean "under that grey box" ? – milad zahedi Jan 08 '16 at 13:41
  • I assume you want the image to take entire screen, is that right ? – milad zahedi Jan 08 '16 at 13:42
  • then you must remove the ActionBar and make your activity full screen. alternatively you can create a full screen dialog. – milad zahedi Jan 08 '16 at 15:44
  • @ShubhamSharma I Edited my answer and put 2 links which can be useful for you. Follow those links and keep me posted. They will solve your problem. – milad zahedi Jan 08 '16 at 16:16
0

The fact that the background and Toolbar are greyed-out makes me think you are displaying your ImageView inside a DialogFragment, not a normal Fragment. DialogFragments are a bit different. Getting them to display full screen is a non-trivial task. If you are not trying to display a Dialog then I suggest using a normal Fragment to display the ImageView.

Side notes:

  1. consider rotating the Bitmap, not the ImageView
  2. consider putting the ImageView in a layout file and inflating that layout file (you already have a LayoutInflater passed to you in onCreateView)
tir38
  • 9,810
  • 10
  • 64
  • 107