Higher res images are being zoomed in and cropped in ImageView - android

I have an image in an ImageView. The ImageView is 40x40 but the actual source image is 80x80 for higher res devices. So, the image was exported at 2x.
However, the image in the ImageView is being zoomed-in on and cropped. Is there any way to prevent this from happening?
Here is my code:
<ImageButton
android:id="#+id/attachment_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="8dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/button_mobile_attachment" />

have you tried with scaleType="centerInside"? also adjustViewBounds seems to be unnecessary set, as you have fixed dimens anyway

Related

Image pixel distort in ImageView Android

I am working with an application in which I have more work with images. I want to show profile pictures and Article images in my app. For article images I have tried scale type of ImageView to "fitcenter or centercrop or fitxy" but nothing works fine. My image pixel's are distorted. I am using Glide library to show image on sever. I have even tried .fitcenter() etc. Glide methods but nothing works so that my image work fine with ImageView.
Code:
<ImageView
android:id="#+id/imgArticle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/blank_image" />
Glide Code:
Glide.with(context).load(articleList.get("article_image"))
.thumbnail(0.5f)
.placeholder(context.getResources().getDrawable(R.drawable.blank_image))
.fitCenter()
.into(imgBanner);
I have tried various methods i.e. fitcenter, centercrop etc. but nothing works.
android:scaleType="fitXY" will stretch your image. You can try this code so that image will not stretch.
<ImageView
android:id="#+id/imgArticle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/blank_image" />
Or you can adjust the height and width as per your UI
<ImageView
android:id="#+id/imgArticle"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/blank_image" />

Adjust Image View to Image (Android Studio)

I would like to know how you adjust the "hitbox" of an ImageView to the Image inside, so that there are no empty spaces around the image. I want to make a game and so it feels odd when you click on an empty space next to the Image but it still counts as "a click on the image". I would really appreciate help.
Thank you in advance.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/soraka"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="#drawable/image"
android:adjustViewBounds="true"
android:maxWidth="300dp"
android:maxHeight="300dp"
android:scaleType="fitXY"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:cropToPadding="false"
android:padding="0dp" />
First of all open your image in some image editor and check if it fills entire canvas. Second - use android:scaleType="fitXY". But be carefull with aspect ratio:
Scale in X and Y independently, so that src matches dst exactly. This
may change the aspect ratio of the src.
Also remove all paddings, margins from ImageView.

Big Imageview Loaded As Small - Not Taking Full Parent

I'm loading a big drawable, to an image view, the imageview is both wrap_content, and in the center inside a RelativeLayout.
I'm loading the drawable using Picasso library .
What to expect : Getting loaded just like the preview (in the preview it's correct ) .
What's happening : Drawable getting resized a lot, ex : it's 100, after loading it's 2, that's pretty small .
What I've tried : Getting device width/height dpi, and use them to resize the image, because i'm getting warning that the image is big (using the max as resize, or the screen height/width, i'm getting the same result ) .
try this one bro.
android scaleType = "fitXY"
<ImageView
android:id="#+id/grid_item_image"
android:layout_width="100dp"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:foregroundGravity="center"
android:layout_height="100dp"/>
This might help
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>

android - loaded image's height it bigger than actual image

I am loading an image from the web with a AsyncTask class and set it to a imageview in my code.
// loading of the image into the ImageView
new DownloadImageTask(MyImageView).execute("ImageURL");
the problem is, every time I load an image, the height of it is different, even though the width and height of the ImageView is warp_content.
I added sort of a border line with the Background and padding to see the actual height of it.
Here is the xml
<ImageView
android:id="#+id/ivBigRecipeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:layout_toRightOf="#+id/ingredientsTitle"
android:background="#52D017"
android:contentDescription="food"
android:padding="1dp" />
in here are the pics
sometimes this happens:
and sometimes this happens:
Any ideas? I want to just have it exactly the actual size of it
thanks!
Try to add android:adjustViewBounds="true" to your ImageView, and it should work.

Android ImageView dynamic ScaleType

I have an Android Activity with an ImageView.
I put the ScaleType of the imageview on CENTER_CROP, so the image itself would not stretch.
<ImageView
android:id="#+id/imgView"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:scaleType="centerCrop"
android:src="#drawable/capture" />
The image that's loaded at first does what I expect, it's cropped to the center, filling the whole ImageView.
Now, if I set the image of the ImageView programatically,
imgView.setImageBitmap(b)
imgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
The picture gets displayed, but it's completely stretched out to fill the ImageView...
AdjustViewBounds has no effect what so ever, nor does anything else.
The difference between the working XML and the not-working java code is that in XML I'm putting the image as a resource, and the code is putting a Drawable in the ImageView from a web-service...
Does anyone have an idea to the solution?
I am not sure but android:scaleType="fitXY" or android:scaleType="fitCenter" may be the solution of your problem.
I solved this by using the original image from my camera-intent. For some reason, all thumbnail bitmaps were stretched out and in landscape mode.

Categories

Resources