用毕加索调整图像大小

时间:2017-02-06 08:33:24

标签: android image 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);

任何关于这样做的想法比编写一个函数来自己调整大小更容易吗?

4 个答案:

答案 0 :(得分:3)

我使用以下方法避免图像拉伸:

.resize(800,0)

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

希望有所帮助

答案 1 :(得分:2)

试试这个:

为您的imageview:

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

答案 2 :(得分:0)

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

答案 3 :(得分:-3)

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

    Glide.with(this)
            .load(imageUrl)
            .centerCrop()
            .override(300, 300)
            .into(imageView);
相关问题