我正在使用https://github.com/hdodenhof/CircleImageView庫,但也嘗試了其他幾種,但沒有幫助。我需要使用畢加索從服務器加載圖像,如mPicasso.load(url).into(mCircularImageView)
。不過,我總是得到這樣的:縮放畢加索位圖以填充CircleImageView中的高度
但我要實現這一點:
嘗試致電resize(100,100)
,fit()
,transform(new CircleTransorm())
,
public class CircleTransform implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size)/2;
int y = (source.getHeight() - size)/2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size/2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
@Override
public String key() {
return "circle";
}
}
沒有任何幫助以上。
我的佈局:
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/account_profile_picture"
style="@style/ProfilePicture"
android:layout_gravity="center_horizontal"/>
風格:
<style name="ProfilePicture">
<item name="android:layout_width">@dimen/profile_picture_size</item>
<item name="android:layout_height">@dimen/profile_picture_size</item>
<item name="android:src">@drawable/profile_picture_placeholder</item>
<item name="civ_border_width">1dp</item>
<item name="civ_border_color">#FF000000</item>
</style>
不幸的是,這並沒有奏效。 – satorikomeiji
然後確保您的佈局設置正確。你能用你的佈局xml更新你的原始問題嗎? – anthonymonori