android中用Fresco实现圆角图片和圆形图片

效果图

img

代码

需要注意的地方用注释给出。

可以在github上下载源码。点我试试

Uri uri = Uri.parse("https://pic4.zhimg.com/03b2d57be62b30f158f48f388c8f3f33_b.png");
        SimpleDraweeView commonImageView = (SimpleDraweeView) findViewById(R.id.commonImageView);
        commonImageView.setImageURI(uri);

        SimpleDraweeView circleImageView = (SimpleDraweeView) findViewById(R.id.circleImageView);
        circleImageView.setImageURI(uri);

        SimpleDraweeView roundedImageView = (SimpleDraweeView) findViewById(R.id.roundedImageView);
        roundedImageView.setImageURI(uri);
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="common image" />
            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/commonImageView"
                android:layout_width="130dp"
                android:layout_height="130dp"
                fresco:actualImageScaleType="centerCrop"
                fresco:placeholderImage="@mipmap/ic_launcher"
                fresco:placeholderImageScaleType="centerCrop" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="circle image" />
            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/circleImageView"
                android:layout_width="130dp"
                android:layout_height="130dp"
                fresco:actualImageScaleType="centerCrop"
                fresco:placeholderImage="@mipmap/ic_launcher"
                fresco:placeholderImageScaleType="centerCrop"
                fresco:roundAsCircle="true" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="rounded image" />
            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/roundedImageView"
                android:layout_width="130dp"
                android:layout_height="130dp"
                fresco:actualImageScaleType="centerCrop"
                fresco:placeholderImage="@mipmap/ic_launcher"
                fresco:placeholderImageScaleType="centerCrop"
                fresco:roundedCornerRadius="25dp" />
        </LinearLayout>
    </LinearLayout>

参考文章

原文

猜你喜欢

转载自blog.csdn.net/aotian16/article/details/53334489