zoukankan      html  css  js  c++  java
  • 自定义圆形图片

    //自定义ImageView

    package com.zcp.map;

    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Path;
    import android.graphics.RectF;
    import android.util.AttributeSet;
    import android.widget.ImageView;

    public class ImgView extends ImageView {

    public ImgView(Context context, AttributeSet attrs) {
    super(context, attrs);

    }
    @Override
    protected void onDraw(Canvas canvas) {
    Path clipPath = new Path();
    int w = this.getWidth();
    int h = this.getHeight();
    clipPath.addRoundRect(new RectF(0, 0, w, h), 200.0f, 200.0f,
    Path.Direction.CW);
    canvas.clipPath(clipPath);
    super.onDraw(canvas);
    }


    }

    //MainActivity

    package com.zcp.map;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;

    public class MainActivity extends Activity {

    private ImgView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    img=(ImgView)findViewById(R.id.img);
    img.setImageResource(R.drawable.x);
    }

    }

    //xml

    <com.zcp.map.ImgView
    android:id="@+id/img"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:scaleType="fitXY" />

  • 相关阅读:
    插入排序的算法分析
    SQL的UNION操作
    二分查找的思路
    怎么看吉他简谱
    一句CSS代码杜绝网站iframe挂马
    关于NewFolder.文件夹无法删除的办法
    C#监听USB接入
    C# 系统服务添加安装
    .NET 实现ISAPI过滤器,指定类型文件防下载
    ASP 简单的异或加密方法
  • 原文地址:https://www.cnblogs.com/hnpy/p/5485740.html
Copyright © 2011-2022 走看看