【问题标题】:Resizing image with picasso用毕加索调整图像大小
【发布时间】:2017-10-24 16:55:19
【问题描述】:

大家好,我遇到了毕加索的问题。我正在尝试从声音云加载图像,但它一直显得拉伸或非常小。这是我的 XML

        <ImageView
            android:id="@+id/album_cover_art"
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/fragment_content_item_top_margin"
            android:scaleType="centerInside"
            android:contentDescription="@string/content_description_image_placeholder"
            android:src="@drawable/placeholder" />

我尝试在内部使用 picasso 的调整大小和居中,但图像看起来很小。

Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerInside().into(mAlbumCoverArt);

使用 picasso 的调整大小和中心裁剪可以保持图像视图大小,但会导致图像看起来被拉伸。

Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerCrop().into(mAlbumCoverArt);

有什么比自己编写函数来调整大小更容易的方法吗?

【问题讨论】:

    标签: android image picasso


    【解决方案1】:

    我避免使用:

    .resize(800,0)
    

    0 作为第二个参数传递,它保留了图像比例。

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      试试这个:

      对于您的图像视图:

      <ImageView
      android:id="@id/img"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:adjustViewBounds="true"  //add this
      android:scaleType="fitCenter" />
      

      picasso 中使用.fit().centerCrop()

      Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).fit().centerCrop().into(mAlbumCoverArt);
      

      【讨论】:

      • 我在使用这个解决方案时遇到了崩溃,堆栈跟踪显示 java.lang.IllegalStateException: Fit cannot be used with resize.
      • 尝试删除您的调整大小..您已经在向 xml 添加宽度高度
      【解决方案3】:

      尝试将高度或宽度设置为固定和其他以包装内容并使用 .fitXY 加载毕加索,不要使用 .调整大小。

      【讨论】:

        【解决方案4】:

        尝试滑翔。 https://github.com/bumptech/glide

            Glide.with(this)
                    .load(imageUrl)
                    .centerCrop()
                    .override(300, 300)
                    .into(imageView);
        

        【讨论】:

        • 问题是关于毕加索不滑翔。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-08
        • 1970-01-01
        • 1970-01-01
        • 2014-03-20
        • 2014-01-16
        相关资源
        最近更新 更多