How to get an imageView on Full Screen in Android? - android

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:
I want screen fully covered with this image with a proper scaling. Therefore, please show me an appropriate solution with proper scaling.

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.

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:
consider rotating the Bitmap, not the ImageView
consider putting the ImageView in a layout file and inflating that layout file (you already have a LayoutInflater passed to you in onCreateView)

Related

IMAGE VIEW ANDROID STUDIO

I have a doubt. While working on an App , I came across this query.
When an Imageview1(smaller size) is dragged and dropped on to Imageview2(bigger size), how to make Imageview1 (fit the area of imageview2), that is, enlarge the Imageview1 automatically to the size of Imageview2.
Instead of doing something so twisted, you can try a simpler solution like:
ImageView2.setImageDrawable(ImageView1.getDrawable());
ImageView1.setVisibility(INVISIBLE); //GONE could be used too, depending on the situation
Overwriting ImageView2 would involve many other operations like moving ImageView1 inside the layout, setting new LayoutParams, etc.
EDIT
Use this:
ImageView1.buildDrawingCache();
Bitmap src = ImageView1.getDrawingCache();
BitmapDrawable destDrawable = new BitmapDrawable(Bitmap.createScaledBitmap(src, ImageView2.getWidth(), ImageView2.getHeight(), false));
ImageView2.setImageDrawable(destDrawable);
In general, it is not a good practice to have views cover other views.
When you do the drag action try this
ImageView.ScaleType(FIT_XY);

Android- Image Rendering

Is there a way the this problem can be fixed? I tried invalidate() but, it still displays the same problem. What happens is that, after opening the page/ the Activity, the images behaves like the one in Figure A. It only renders to my desired layout (Figure B) after scrolling it back and forth.
What I'm trying to do is set the width and heigth of the image during runtime. So this is also in relation to my previous questions : Images in my HorizontalListView changes it size randomly and ImageView dynamic width and height which received a very little help.
Any tips regarding this matter, please?
EDIT: btw, my classes are:
MyCustomAdapter (extends baseadapter, this calls the displayimage() from ImageLoader ),
MyActivity and
ImageLoader (this is where my image url are loaded, decoded, displayed asynchronously)
Im also confused as to where i will set the height and width of the imageView. For now, i set it at ImageLoader. It was okay. but i dont know if i did the right thing.
If you want to set the width and height manually at runtime, grab a reference to the ImageView's LayoutParams AFTER the View has been measured by the layout system. If you do this too early in the rendering phase, your view's width and height as well as its parent view and so on will be 0.
I have some code in an open source library that might help you. The process is two parts:
Set up an OnPreDrawListener attached to the ViewTreeObserver for your control. My example does this inside of a custom control, but you can do this in your activity as well.
Inside the onPreDraw method, your image and it's parent will now have their width and height values assigned to them. You can make your calculations and then set your width and/or height manually to the LayoutParams object of your view (don't forget to set it back).
Check out this example where I'm applying an aspect ratio to a custom ImageView just before it's rendered to the screen. I don't know if this exactly fits your use case, but this will demonstrate how to add an OnPreDrawListener to a ViewTreeObserver, removing it when you're done, and applying dynamic sizing to a View at runtime
https://github.com/aguynamedrich/beacon-utils/blob/master/Library/src/us/beacondigital/utils/RemoteImageView.java#L78
Here's a modified version that removes my particular resizing logic. It also grabs the ViewTreeObserver from the imageView, which is a more likely scenario if you're not implementing a custom control and you only want to do this in the Activity
private void initResizeLogic() {
final ViewTreeObserver obs = imageView.getViewTreeObserver();
obs.addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
dynamicResize();
obs.removeOnPreDrawListener(this);
return true;
}
});
}
protected void dynamicResize() {
ViewGroup.LayoutParams lp = imageView.getLayoutParams();
// resize logic goes here...
// imageView.getWidth() and imageView.getHeight() now return
// their initial layout values
lp.height = someCalculatedHeight;
lp.width = someCalculatedWidth;
imageView.setLayoutParams(lp);
}
}

Fitting DialogFragment to image size

I have a DialogFragment with a ViewPager that shows some pictures. The problem that there's a weird black stripe on top, and these pictures are deformed.
This is what I currently have, and as you can see, the picture doesn't really look good and there's a weird black stripe on top of the dialog.
This is how it should look, without black stripes and the picture fits the width of the screen.
How could I do this?
Thanks a lot in advance.
To get rid of the black frame at the top, try calling the DialogFragment.setStyle(int style, int theme) method in your DialogFragment.onCreate(Bundle savedInstanceState) method, e.g. setStyle(DialogFragment.STYLE_NO_TITLE, 0) or setStyle(DialogFragment.STYLE_NO_FRAME, 0).
I'm also having problems like you getting a DialogFragment to be a certain width. The layout_width value of my DialogFragment (as specified in my DialogFragment's xml layout file) seems to get overridden somewhere and sometimes my DialogFragment expands and sometimes it shrinks depending on the content. A bit of a hack I know but the best I've been able to come up with is to call the getDialog().getWindow().setLayout(int width, int height) method in my DialogFragment.onResume() method, e.g. getDialog().getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).
To then resize your images to fit within your DialogFragment, use the ImageView.setScaleType(ImageView.ScaleType scaleType) method as the other answers in this thread have alluded to.
You could set the imageview android:scaleType="centerCrop" or perhaps just setting the height of the viewpager and images to wrap_content.
you should set the attribute android:adjustViewBounds="true" in your imageView

How to center a Imageview on the screen? (with java code)

atm i'm using this code, but this code doesn't works for me, because the code is stretching the Image on the screen, i dont want that, i need that the image uses his real size (200x210)
FrameLayout fl = new FrameLayout(this.getApplicationContext());
splash = new ImageView(getApplicationContext());
splash.setImageResource(R.drawable.logo2);
fl.addView(splash);
fl.setForegroundGravity(Gravity.CENTER);
fl.setBackgroundColor(Color.BLACK);
setContentView(fl);
How to do it without making a giant image that it is using all the screen?
You have to specify scalType if you don't want imageview to stretch your image.
splash.setScaleType(ScaleType.CENTER);
use this properties of ImageView as shown here:
splash.setAdjustViewBounds(true);
and tell me if it is working.

Moving views inside a layout/view in Android

I have more than one question, but I'll start with the more important and problematic one:
I have a FrameLayout with a ImageView inside it. I need to get the size of the "usable area" of the screen my activity is ocupping, so I set the onSizeChanged on my View (I extended the ImageView class). Everything worked fine here. Now I have a 1000x1000 image that I want to show on the screen, but without scaling. I want it to be clipped, really. If I set the ImageView dimensions using viewObject.setLayoutParams(new Gallery.LayoutParams(1000, 1000)); I get the image being showed correctly, but then the onSizeChanged event returns me always the "1000 x 1000" custom size rather than the real screen size value.
Any ideas of how can I show an image with its real size (no scale!) and still get the view to report the screen available space? I can change the layout as needed as well, of course.
. Amplexos.
Are you asking to get the dimensions of the ImageView? If so then you can get that using getLocalVisibleRect. Here's roughly how it's done:
ImageView yourImageView;
public void onCreate(...){
setContentView(...)
yourImageView = (ImageView) findViewById(...);
(...)
}
getImageViewSize(){
Rect imageViewSize = new Rect();
yourImageView.getLocalVisibleRect(imageViewSize);
// imageViewSize now has all the values you need
Log.d("Your log tag", "ImageView width = " + (imageViewSize.right -
imageViewSize.left));
}
There is however a catch. You have to make sure that you don't try to get the size of the view until after view is finished being laid out on the screen. In other words, if you try to get its size in onCreate, its size will be 0. You have to get it afterwards, for example at the same time as you resize your image, assuming that's done with a button. (If you're using a SurfaceHolder you can also call it during the surfaceCreated callback, but I doubt you're using one of those...)

Categories

Resources