最新国产好看的视频,伊人天堂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)論

云梦县| 大足县| 如东县| 赣州市| 荔浦县| 渭源县| 太仓市| 睢宁县| 拜泉县| 微博| 江山市| 万年县| 平江县| 怀宁县| 靖安县| 印江| 台中县| 加查县| 石嘴山市| 新巴尔虎右旗| 东丽区| 新兴县| 临城县| 栖霞市| 沽源县| 邳州市| 岑巩县| 白朗县| 临沂市| 泸西县| 恩平市| 泸水县| 普陀区| 温州市| 新昌县| 兴海县| 岢岚县| 扎兰屯市| 惠东县| 都江堰市| 阆中市|