set NetworkImageView with Volley disable holder of the image - java

I use a adapter to load a lot of images witch have a holder, the problem when I scroll the image is loading and NetworkImageView holder is not shown anymore.
in adapter I use setImageUrl to set content of image
holderElementGridView.drawable2.setImageUrl(url,VolleySingleton.getInstance(mContext).getImageLoader());
and xml:
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="100"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:src="#drawable/iphone_feuilledematch_imagebackground" >
</com.android.volley.toolbox.NetworkImageView>
the iphone_feuilledematch_imagebackground is disable when volley download image.
How can I keep the default drawable source until volley finish the download of drawable ?

You can use Picasso instead of Volley, it works the way you want.

Related

why my first app doesn't show up on my phone?

I'm creating my first hello word apps, the first one shows just a hello word test and it worked on my phone, but i put a picture in the second one and run it the phone shows: the app has stopped ; my app looks on the xml design exactly how i wanted it !! (my phone has android 7 and i made the app with android 4)
the picture that i tried to show has a 3096x4128 resolution, but when i tried other picture that has less resolution has worked , i don't know if it's just a coincidence !i tried to change the app's android but same problem!
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="#drawable/hugo" />
<TextView
android:text="What a Picture!"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/white"
android:padding="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="By AYMEN "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:textSize="36sp" />
I think you are getting OutOfMemory Error. To avoid this you can use the Picasso or Glide libraries
implementation 'com.squareup.picasso:picasso:2.71828'
In Picasso you can use the .fit() method to optimize the image and load it into your ImageView without losing the image quality.
Picasso
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
you have to used image size is less than 2MB. This is the main reason to stop the app. So try to resize it & then used it in ImageView

How to remove any xml property from java code in Android

I have set these properties of an ImageView
<ImageView
android:id="#+id/image_view"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.0"
android:adjustViewBounds="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
app:layout_constraintBottom_toBottomOf="parent"
android:scaleType="centerCrop"
/>
Now from Java code, I want to remove scaleType property form this image view. I dont want any scale type to be on this ImageView.
Is it possible to achieve this?
If You Not Set Any Scale Type Then For Image View Default Scale Type is FIT_CENTER
//So to remove other scale types and set to default use
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
This is how you set or change the Image View scale type at runtime from within Java:
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setScaleType(ScaleType.CENTER);
You can refer to this documentation page for the possible ScaleType options.

ImageView centerCrop overflows ImageView bounds?

I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="top|center"
android:background="#drawable/rounded_corner"
android:layout_marginTop="50dp"
android:layout_width="250dp"
android:layout_height="350dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="270dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:src="#drawable/card_image"
android:layout_gravity="top"
android:layout_marginTop="0dp"/>
</FrameLayout>
The image should fill the image with its rectangle and scale it keeping its aspect ratio. It works fine when I do not move the view:
But, when I move the view, the image is drawn outside of its bounds:
I am using this library to move the card.
How do I prevent that the ImageView draws its image outside its bounds?
I use this library with Picasso, something like the example below. I've modified the code you provided a bit to keep it familiar.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="top|center"
android:background="#drawable/rounded_corner"
android:layout_marginTop="50dp"
android:layout_width="250dp"
android:layout_height="350dp">
<!-- Note that I've deleted a lot of properties from the ImageView -->
<!-- This is because Picasso will do a lot of that for us -->
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="270dp"
android:src="#drawable/card_image"
/>
</FrameLayout>
When you've inflated the view, you can simply find the view using findViewById, as you'd usually do.
ImageView imageView = (ImageView) inflatedView.findViewById(R.id.image_view);
// Here comes the Picasso bit
Picasso.with(getActivity()) // You have to provide a Context
.load(R.drawable.card_image) // Can be a Uri, File or String path as well
.into(imageView); // Use .into(ImageView view, Callback callback) to register a listener for the image loading.
This will simply put the image into the ImageView without modifying it. You can add .centerCrop(), .fit() (example below) and other nifty methods to edit the image to the container properties automatically. Since you use centerCrop in your example I won't go into those, but refer to the Picasso github page I provided at the top for futher documentation.
To centercrop or fit the image, you add the method between load() and .into():
Picasso.with(getActivity())
.load(R.drawable.card_image)
.centerCrop()
.fit()
.into(imageView);
Another great feature of Picasso is how it deals with slow or non-successful loading: you can add placeholders and error resources:
Picasso.with(getActivity())
.load(R.drawable.card_image)
.placeholder(R.drawable.loading_image)
.error(R.drawable.error_image
.into(imageView);
Good luck!

i Can't Resize Image in XML Android

Why I can't display images in a large size, its results even smaller, is there something wrong with my XML code? or errors are in the java code? And i have "[Accessibility] Missing contentDescription attribute on image" on my XML code in ImageView
This my code :
Detail.xml
<ImageView
android:id="#+id/ivPosterImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:maxHeight="300dp"
android:src="#drawable/large_movie_poster" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ivPosterImage"
android:layout_marginTop="10dp" android:id="#+id/scrollView1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Activity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_box_office_detail);
// Fetch views
ivPosterImage = (ImageView) findViewById(R.id.ivPosterImage);
....
Picasso.with(this).load(movie.getLargePosterUrl()).
placeholder(R.drawable.large_movie_poster).
into(ivPosterImage);
Please help me ...
Its clearly looking that your downloaded image have very small height and width dimension and you have settled the dimension around wrap_content. That's why you are getting this small icon instead of full image.
And again image download libs always use image attribute setSource in their code, which also set image around wrap_content.
Now you have 2 choice to show image wider:
set width = match parent,
height = fixed(any value as per your choice like 100 dp ,200 etc), i have not fixed the width because thats goona create exception on small or large screns.
set image background instead of image src that is by default set by image download libs.
Hopefully this will resolve your issue.

How do I make my ImageView a fixed size regardless of the size of the bitmap

So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file:
<ImageView android:id="#+id/recipeImage"
android:maxHeight="64px"
android:maxWidth="64px"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"/>
But,nothing has worked.
Just delete the maxHeight and maxWidth attributes and enter your units in layout_width and layout_height appropriately. But do not use the px unit - use dp instead, because these are device-independent.
This will fit the image in the specified height and width, irrespective of image size.
<ImageView
android:id="#+id/image5"
android:layout_width="300dp"
android:layout_height="200dp"
android:src="#drawable/image_1"
android:scaleType="fitXY"/>
Get ImageVIews as facebook posts.
Glide.with(context).load(link)
.placeholder(R.drawable.aboutlogo)
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);`
<ImageView
android:id="#+id/img1"
android:src="#drawable/ic_menu_camera"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"/>

Categories

Resources