ImageView的'使用adjustViewBounds的问题

时间:2017-11-23 09:40:12

标签: android imageview android-imageview android-glide

我试图将图片加载到ImageView这个大小可变的图片中,但是当纵横比维持在" adjustViewBounds" ,宽度较小,高度较大的图像显示得太大。我想限制身高。

我希望图像显示全宽和可变高度,同时保持纵横比。当我尝试将图像的大小调整为原始图像的60%时,它仍然使用相同的空间并且变得太大。

实施代码:

 <ImageView
        android:id="@+id/iv_HomeFragment_PostGallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_HomeFragment_ReadMore"
        android:adjustViewBounds="true"/>

GLIDE代码:

Glide.with(currentFragment)
                .load(url)
                .asBitmap()
                .dontAnimate()
                .placeholder(R.drawable.placeholder)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .error(R.drawable.error_image)
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        Bitmap resizeBitmap = resize(resource,(int)(width * 0.4f),(int)(height * 0.4f));
                        viewHolder.ivGalleryPic.setImageBitmap(resizeBitmap);
                    }
                });

1 个答案:

答案 0 :(得分:0)

您可以尝试此操作来保持宽高比

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/unnamed" />
        </LinearLayout>
    </ScrollView>