Android: Loading image using Glide leaves whitespace on both ends - android

I am loading image from server using Glide. The image size is 600 X 400px. Now my image view is as follows
<ImageView
android:id="#+id/imageView76"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="#dimen/margin_eight"
android:layout_marginTop="#dimen/margin_eight"
android:layout_marginEnd="#dimen/margin_eight"
android:adjustViewBounds="true"
app:bindImageUrl="#{newsModel.images}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
This is how I am loading image:
Glide.with(view.context).asBitmap().load(imageUrl).apply(RequestOptions().optionalCenterInside()).into(view)
But the result is like this:
As show, white space appears on both ends of image. How can I make this image use full width of imageview, while maintaining aspect ratio

androd:scaleType=“fit_xy”
you this add to imageviewthis attribute
It will help you the image full the whole ImageView

Related

How to handle variable height image in RecyclerView?

I am making a chat application. For that, if the message is of image type, I want to wrap the height and fix the width. But the problem is that since image takes some time to load, there is a shift in chat messages until the image is loaded and so there is a jerk. How do I handle this?
<android.support.constraint.ConstraintLayout
android:id="#+id/parent_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/send_message_box"
android:maxWidth="228dp">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/iv_message"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="200dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:padding="11dp"
android:visibility="gone" />
</android.support.constraint.ConstraintLayout>
This is the image layout I am using.
You could fix the height and display a placeholder image till the image gets loaded. You get this functionality of displaying a placeholder image(till the image gets loaded) with Picasso, check this https://square.github.io/picasso/
You can set up an initial height using a default image while your images are getting downloaded. After the image is downloaded, it will take the height of the image if you set the height as wrap_content. Hence you need to modify your ImageView like the following.
<ImageView
android:id="#+id/iv_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#mipmap/ic_image_loader_placeholder" />
Please modify the ImageView as per your requirement.
You might also look at this Github project where I have implemented a similar idea. I had to call an API of Flickr and load the images into the RecyclerView. Hope that helps!

how to fix stretching image in image view in android when i use fitxy Scale type in android

<ImageView
android:id="#+id/bigimages"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_below="#+id/productTitle"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="40dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/bath_and_body_1" />
Glide.with(this)
.load("https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg")
.placeholder(R.drawable.cancel_icon)
.into(bigimages);
https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg
this is my code and image URl i have to display full image without streching but i am not able to display its stretched please suggest me how to fix it . below is current image which is stretched
enter image description here
how to fix there is stretching in text yellow....
YOu can try :
android:scaleType="fitXY"
android:adjustViewBounds="true"
Change to
android:scaleType="centerCrop"
or
Glide.with(this)
.load("https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg")
.placeholder(R.drawable.cancel_icon)
.centerCrop()
.into(bigimages);
Of the various scaleType options, fitXY is specifically made to stretch the image. It will make sure that the entire image is stretched/shrunk to fit in exactly the space provided.
You probably want centerInside; this will make sure that the entire image fits within the view, and will not distort the aspect ratio. If your view is square and the image is rectangular, centerInside will scale the image down so that it fits inside the view, meaning either the top+bottom or left+right will be empty.
Alter your Glide implementation with:
Glide.with(this)
.load("https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg")
.override(width, height) //set width & height as you want
.palceholder(R.drawable.cancel_icon)
.into(bigimages);
References:
Glide Image Resizing & Scaling
Glide Documentation

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"/>

Strech To Fit Volley NetworkImageView

I'm using NetworkImageView to display images , the problem is the width and the height of the image is not fitting with the NetworkImageView , and the image will take it's original size and a white space will appear in the NetworkImageView . I don't wan't to change the image size as well ..
<com.android.volley.toolbox.NetworkImageView
android:layout_gravity="top"
android:id="#+id/thumb2"
android:layout_width="match_parent"
android:layout_height="170dp" />
If you want the image size to stay same then set layout_width & height to wrap_content.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
otherwise just add android:scaleType with appropriate value that suits you.
android:scaleType="fitCenter"
or
android:scaleType="centerCrop"
You can see full list of available values here http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

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.

Categories

Resources