首页 > 其他 > 详细

自定义ImageView,圆形图

时间:2016-05-04 10:40:01      阅读:277      评论:0      收藏:0      [点我收藏+]
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);
    }

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <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" />

</RelativeLayout>
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);
    }


}

 

自定义ImageView,圆形图

原文:http://www.cnblogs.com/yr520/p/5457419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!