最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)圓角圖片的方法

 更新時(shí)間:2021年04月22日 14:41:51   作者:天地神仙  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圓角圖片的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)圓角圖片的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

創(chuàng)建類CustomRoundAngleImageView

public class CustomRoundAngleImageView extends AppCompatImageView {
    float width, height;

    public CustomRoundAngleImageView(Context context) {
        this(context, null);
        init(context, null);
    }

    public CustomRoundAngleImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        init(context, attrs);
    }

    public CustomRoundAngleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        if (Build.VERSION.SDK_INT < 18) {
            setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        width = getWidth();
        height = getHeight();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (width >= 20 && height > 20) {
            Path path = new Path();
            //四個(gè)圓角
            path.moveTo(20, 0);
            path.lineTo(width - 20, 0);
            path.quadTo(width, 0, width, 20);
            path.lineTo(width, height - 20);
            path.quadTo(width, height, width - 20, height);
            path.lineTo(20, height);
            path.quadTo(0, height, 0, height - 20);
            path.lineTo(0, 20);
            path.quadTo(0, 0, 20, 0);
            canvas.clipPath(path);
        }
        super.onDraw(canvas);
    }
}

布局代碼

<com.example.myapplication.CustomRoundAngleImageView
      android:id="@+id/we_image"
      android:layout_width="42dp"
      android:layout_height="42dp"
      android:layout_marginLeft="16dp"
      android:layout_marginTop="10dp"
      android:src="@mipmap/ic_launcher"
      android:layout_marginBottom="10dp"
      android:layout_gravity="center"
      android:scaleType="centerCrop" />

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

凤冈县| 蕉岭县| 同德县| 樟树市| 永嘉县| 屏东县| 新绛县| 朝阳县| 铜梁县| 仁寿县| 长顺县| 合川市| 宽城| 锡林郭勒盟| 克什克腾旗| 南京市| 汝阳县| 嘉鱼县| 赞皇县| 普格县| 双峰县| 灵寿县| 荣昌县| 观塘区| 手游| 平安县| 凤山县| 长子县| 上饶县| 汉沽区| 五河县| 甘洛县| 平谷区| 灵丘县| 巴彦淖尔市| 墨玉县| 汉中市| 紫阳县| 武胜县| 盐池县| 玛曲县|