用毕加索调整图像大小
Resizing image with picasso
大家好,我 运行 遇到了毕加索的问题。我正在尝试从声音云加载图像,但它一直显得拉伸或非常小。这是我的 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.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerInside().into(mAlbumCoverArt);
使用毕加索的调整大小和居中裁剪可保持图像视图大小,但会导致图像出现拉伸。
Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerCrop().into(mAlbumCoverArt);
有什么比自己编写函数来调整大小更容易的方法吗?
试试这个:
对于您的图像视图:
<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);
试试 Glide。
https://github.com/bumptech/glide
Glide.with(this)
.load(imageUrl)
.centerCrop()
.override(300, 300)
.into(imageView);
我使用 :
避免了图像拉伸
.resize(800,0)
将 0
作为第二个参数传递,它保留了图像比例。
希望对您有所帮助
尝试将高度或宽度设置为固定和其他以包装内容并使用 .fitXY 加载 Picasso,不要使用 .调整大小。
大家好,我 运行 遇到了毕加索的问题。我正在尝试从声音云加载图像,但它一直显得拉伸或非常小。这是我的 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.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerInside().into(mAlbumCoverArt);
使用毕加索的调整大小和居中裁剪可保持图像视图大小,但会导致图像出现拉伸。
Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerCrop().into(mAlbumCoverArt);
有什么比自己编写函数来调整大小更容易的方法吗?
试试这个:
对于您的图像视图:
<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);
试试 Glide。 https://github.com/bumptech/glide
Glide.with(this)
.load(imageUrl)
.centerCrop()
.override(300, 300)
.into(imageView);
我使用 :
避免了图像拉伸.resize(800,0)
将 0
作为第二个参数传递,它保留了图像比例。
希望对您有所帮助
尝试将高度或宽度设置为固定和其他以包装内容并使用 .fitXY 加载 Picasso,不要使用 .调整大小。