【问题标题】:ImageView' issues using adjustViewBoundsImageView 使用 adjustViewBounds 的问题
【发布时间】:2018-05-07 05:18:37
【问题描述】:

我正在尝试将图像加载到大小可变的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.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);
                    }
                });

【问题讨论】:

  • 尝试android:scaleType="fitCenter",如果它不起作用尝试不同的比例类型值。
  • @SaranSankaran 不工作兄弟。尝试了每个“scaleType”

标签: android imageview android-imageview android-glide


【解决方案1】:

你可以试试这个来保持纵横比

    <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>

【讨论】:

    猜你喜欢
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2021-11-26
    • 1970-01-01
    相关资源
    最近更新 更多