Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide make ImageView wrap_content useless and no animatiion using target

I'm load a picture using Glide in my project, but I found a strange thing. When I use into(ImageView), the ImageView displays not the same with what when using into(new BitmapImageViewTarget(centerImageView))

This is my layout:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <ImageView
        android:id="@+id/center_image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>

When I use :

String imageUrl = "http://7xlz1k.com1.z0.glb.clouddn.com/feedback-201604229711.png";
Glide.with(this).load(imageUrl).into(centerImageView);

The ImageView's wrap_content doesn't work, it displays like this: enter image description here

But when I use :

    Glide.with(this).load(imageUrl).asBitmap().into(new BitmapImageViewTarget(centerImageView));

The ImageView looks :

enter image description here

The image contained in the imageUrl is a 120*120 picture.

And when I use the BitmapImageViewTarget, the default animation doesn't work.

Three questions:

  1. Why is there the difference between the two methods?

  2. How can I make the ImageView's wrap_content useful when using the first method?

  3. And How can I make the default animation enable when using the BitmapImageViewTarget?

like image 425
L. Swifter Avatar asked Apr 22 '16 09:04

L. Swifter


1 Answers

I will try give a solution for your second question:

  1. How can I make the ImageView's wrap_content useful when using the first method?

I managed to make wrap_content working by adding adjustViewBounds to the ImageView's layout:

<ImageView
            android:id="@+id/center_image_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:adjustViewBounds="true" />
like image 161
Var Droid Avatar answered Sep 21 '22 19:09

Var Droid