13

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?

L. Swifter
  • 3,179
  • 28
  • 52

2 Answers2

22

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" />
nikis
  • 11,166
  • 2
  • 35
  • 45
Var Droid
  • 244
  • 3
  • 5
0

My Glide version : 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);
    }
Tom
  • 333
  • 2
  • 8