I used picasso as image library for my application. Images were loading a bit slowly so i decided to remove placeholder and it started loading faster.
How come if placeholder is not there its loading faster. But problem is if I remove placeholder. Before loading image it squeezes that area and once image loads it takes proper area filled with image.
My Imageview code below:
<com.wallie.imagview.SquareImageView
android:id="#+id/imageone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#drawable/border_image_view"
android:padding="1dp" />
Picasso code i used earlier (loads image a bit slower ):
Picasso.with(context).load(url)
.placeholder(R.drawable.image_loading)
.into(imageView);
Picasso code i used now (loads image faster):
Picasso.with(context).load(url)
.into(imageView);
But problem is it squeezes space for image without placeholder and my spinner for all images get in one place.
Related
I've started an app where I'm getting images from a RESTful server in response to the user clicking on another component on the screen. I've set it up so that it gets the data back, creates a byte array and displays that on the screen - all good.
However I've learnt that this may have memory leaks and the best way to load images is with glide. I've got the simple glide working but it has problems. Specifically when I reload an image onto an image view the component shrinks to a height of zero and then resizes again. How can I say to Glide - keep the component the same size during the transition? Crossfade doesn't work and I can't see anything that can do this.
EDIT
The code with the glide is as follows:
Glide.with(this)
.load(Base64.decode(image, Base64.DEFAULT))
.into((ImageView) findViewById(R.id.cutoutImageView));
The image variable is a string containing the images retrieved from a RESTful service.
The XML defining the imageview is as follows:
<ImageView
android:id="#+id/cutoutImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/annotatedImageView"
android:layout_marginLeft="10px"
android:layout_marginTop="10px"
android:background="#color/colorPrimary"
android:padding="1dp"/>
Note that I can't hardcode the size of the image view because I don't know what size image I'll be getting from the RESTful service until I get it. I do know that once I get one image then the subsequent images will all be the same size though.
Another issue is that glide wants to scale the iamge - I don't I want to show the image at the size I get it. How do I do that?
I'm using this news api to pull the json data into my app and render it in my articlerecycler adapter class.
From the api there is a json value urlToImage that contains the thumbnail that I need to render. Currently I have a working list of 20 or so articles displaying the author, title, description, etc.
What is the best way to show the thumbnails as well?
Is using ImageView widget the best way to handle this?
For example,
<ImageView
android:id="#+id/thumbnailIv"
android:layout_width="94dp"
android:layout_height="93dp"
android:layout_weight="1"
android:contentDescription="#string/urlToImage"
android:scaleType="fitCenter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/placeholder_image" />
I've found through other posts that picasso is a good way to lazy load images, specifically thumbnails.
// load the image with Picasso
Picasso.get()
.load("") // load the image
.into(thumbnailIv) // select the ImageVi
}
Yes use ImageView and use library like Glide or picasso to load image into ImageView from the url
GlideApp.with(context)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.DATA) //optional
.placeholder(R.drawable.default_image) //optional
.error(R.drawable.default_image) //optional
.into(holder.imageNews);
With ImageView you can control ScaleType another useful property is android:adjustViewBounds="true" which will maintain aspect ratio . If you use use linear/relative and set image as background then you cannot control these properties
I know this question was asked already, but their answers didn't solve my problem.
I am using Glide in GridView
when GridView displays the pictures, it looks like this
I kept waiting but nothing changed. Then after scrolling the GridView, all the images suddenly appeared as shown below.
So, how to get better quality images without having to scroll? Is there any alternative solution for this problem?
I wrote my Glide code like this
Glide.with(activity)
.load(R.drawable.xyz)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.img_hold)
.into(imgView);
found the problem. the image get blur or pixelated is because you doesn't set a fix width value in my imageview like this :
android:layout_width="wrap_content"
android:layout_height="100dp"
after i give it a fixed value like this:
android:layout_width="170dp"
android:layout_height="100dp"
all image is loaded nicely.
but I had tested on picasso lib, they load all image nicely although with android:layout_width="wrap_content"
I'm trying to load an image from filesystem into an imageView with the ion library.
When I'm using the following code:
Ion.with(imageView)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load(uri);
it (sometimes) results in a kind of blurry image.
When not using ion like the following the pictures appear sharply:
imageView.setImageBitmap(BitmapFactory.decodeFile(uri.toString()));
Is there a standard compression coming with ion that I can disable?
Strangely not every picture is blurry when using ion, e.g. I have two identical images, only with another name. When I load them into the imageView with ion one is blurry, one is not.
Any help or tips are appreciated!
Ion tries to load the image to fit the bounds of the ImageView. So make sure your ImageView is sized properly in your layout. Alternatively, if you use adjustViewBounds=true to indicate the ImageView is adjusted by the image contents, it won't do that. Or alternatively smartsize(false).
Try this,
Ion.with(context)
.load(url)
.withBitmap()
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.intoImageView(imageView);
Picasso allows me to resize an image. Is there a mechanism for resizing the placeholder? The following is not sufficient. What am I missing?
Picasso.with(mContext).load(url).placeholder(R.drawable.imageview_holder).resize(200, 200).into(imageview);
What I found that works for me is to resize the placeholder (and error image) directly with the ImageView using android:scaleType="fitCenter" in the XML. Then I can still use Picasso to resize and center the downloaded image.