Glide makes ImageView wrap_content useless and doesn't use animation

I upload a picture using Glidein my project, but I found a strange thing. When I use into(ImageView), it is ImageViewdisplayed differently than 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);

ImageView wrap_contentdoes not work, it looks like this:enter image description here

But when I use:

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

ImageView looks like:

enter image description here

The image contained in imageUrlis an image sized 120 * 120.

And when I use BitmapImageViewTargetanimation by default does not work.

Three questions:

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

  2. How do I make ImageView wrap_contentuseful when using the first method?

  3. BitmapImageViewTarget?

+7
2

:

  1. ImageView wrap_content ?

wrap_content , adjustViewBounds ImageView:

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

My Glide: 4.9.0

<!--  my ImageView:  -->
<ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    public static void showRoundedCornerImage(ImageView imageView, 
                       String url, int maxHeight,int maxWidth,int corner) {
        Context context = imageView.getContext();
        corner = OsUtils.dp2px(context, corner);
        maxHeight = OsUtils.dp2px(context, maxHeight);
        maxWidth = OsUtils.dp2px(context, maxWidth);

        Glide.with(context)
                .load(url)
                .fitCenter()
                .transform(new RoundedCorners(corner))
                .override(maxWidth,maxHeight)// look here
                .into(imageView);
    }
0

All Articles