[英]Crop image as square with picasso
如何在 Android 上使用 picasso 庫將圖像裁剪為正方形?
我需要以下內容:
我也需要
下面的項目為畢加索提供了很多不同的變換
https://github.com/wasabeef/picasso-transformations
您感興趣的名為CropSquareTransformation
,您可以使用以下代碼應用它
Picasso.with(mContext)
.load(R.drawable.demo)
.transform(transformation)
.transform(new CropSquareTransformation())
.into(holder.image);
您可以添加依賴項或復制並粘貼您需要的類。
使用自定義圖像視圖:
public class SquareImageView extends android.support.v7.widget.AppCompatImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); //Snap to width
}
}
在您的 xml 中:
<com.my.package.SquareImageView
android:layout_width="match_parent"
android:layout_height="wrap_content">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.