PhotoView fit screen height maintain aspect ratio - android

I cant scaletype for my PhotoView that lets me pan side to side on an image while being full-screen, without cropping the sides using Photo.ScaleType.CENTER_CROP. How would I go about doing this?
This is what I want (where the user can pan side to side to view the whole image):
This is what I get (when using ScaleType.CENTER_CROP, which is closest to what I'm going for but because of the CROP, doesnt allow panning side to side.):

you can use a this ImageViewZoom.
if you don't want to use lib see the codes and try to scale canvas

I fixed it by using a PhotoViewAttacher like this:
ImageView imageView = (ImageView) findViewById(R.id.preview);
PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(imageView);
photoViewAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP)
and then using an ImageView (id.preview) with the ScaleType in the XML set as Matrix. (otherwise it wont work)

Related

Gravity TOP not working when using ScaleType.CENTER_CROP in a ImageView

I have an activity that shows a imageview with a random bitmap from assets folder. I'm loading the image view with this code:
ImageView imv = new ImageView(ctx);
imv.setAdjustViewBounds(true);
imv.setScaleType(ImageView.ScaleType.CENTER_CROP);
imv.setImageBitmap(this.myBitmap);
Also the gravity of the image is set to top of the screen with layout params containing Gravity.TOP
I must use CENTER_CROP because my image sometimes is longer than the height of the screen, and because some other particualirities of my app. I can't use FIT_XY because it deforms my image. I tryed removing center_CROP and did not work, because i want that the image haves the full width of the screen, and without center_crop the image is scaled down.
The problem is that when the bitmap haves more height than the screen height, the image is not starting on the top of the screen, some portion of the upper zone of the image is not being displayed.
How can i avoid that problem?
Thanks

Android ImageView pan animation with scaleType centerCrop

I have an ImageView set to scaleType="centerCrop" , I am trying to create an animation which pans this ImageView to its left and right edges, which are outside of the bounds of the view.
How would I do this?
Normally when animating I have the full view on screen already, but in this case the ImageView itself is rendered but its source is scaled outside the bounds of its view. So if I was just animating the VIEW itself I won't be accessing the source.
This may have something more to do with animating on a canvas within an imageview, instead of moving the X, Y position of the imageview itself. Insight appreciated
Regarding the "too broad" allegation to close this question, yeah, it isn't.
I was able to do this with the KenBurnsView library object
https://github.com/flavioarfaria/KenBurnsView
I modified my version to use my custom imageview objects which extend NetworkImageView from Volley

TouchImageView Scaletype centerCrop ??

I have an imageview where i have implemented the TouchImageView class for zoom functionality. But i'm not able to set the scaletype. I want the initial scaletype to be centercrop but i dosen't work.
When i try
img.setScaleType(ScaleType.CENTER_CROP);
the zoom functionality stops working and the image becomes center-cropped. I want both to work together.
How can i make the initial image to be center cropped that is being selected from my SDcard into an imageview with zoom functionality.
The patch for supporting scale types other than FIT_START and FIT_XY have been made. If anyone needs help with this please refer to this :
https://github.com/MikeOrtiz/TouchImageView/commit/475b552b468c1da10d6802cefaa00cf5e39b27d1
Has anyone tried this patch and the getZoomedImageFromSource() with scaleType centre crop
the bitmap it returns does not match the zoomed image.

How to use scaletype of a ImageView as center and matrix at the sametime?

Is there a way to set the ScaleType of a ImageView as CENTER using Matrix ScaleType?
I'm in need of Center orientation of an image in the ImageView. Problem occurs when I set the size of the ImageView larger than the screen say 1000dp. By doing so my image sticks to the corners.
If I use layout_margins, I'm not able to pinch and zoom the image properly.
Please help me find a solution.

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.

Categories

Resources