专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 图形/图像

继承ImageView在下面画圆

发布时间:2011-06-27 20:26:55 文章来源:www.iduyao.cn 采编人员:星星草
继承ImageView在上面画圆
public class CustomView extends ImageView{ 
public CustomView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
} 
public CustomView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 
public CustomView(Context context) { 
    super(context); 
} 
boolean drawGlow = false; 
//this is the pixel coordinates of the screen 
float glowX = 0; 
float glowY = 0; 
//this is the radius of the circle we are drawing 
float radius = 20; 
//this is the paint object which specifies the color and alpha level  
//of the circle we draw 
Paint paint = new Paint(); 
{ 
    paint.setAntiAlias(true); 
    paint.setColor(Color.WHITE); 
    paint.setAlpha(50); 
}; 
 
@Override 
public void draw(Canvas canvas){ 
    super.draw(canvas); 
    if(drawGlow) 
        canvas.drawCircle(glowX, glowY, radius, paint); 
} 
@Override 
public boolean onTouchEvent(MotionEvent event){ 
    if(event.getAction() == MotionEvent.ACTION_DOWN){ 
        drawGlow = true; 
    }else if(event.getAction() == MotionEvent.ACTION_UP) 
        drawGlow = false; 
 
    glowX = event.getX(); 
    glowY = event.getY(); 
    this.invalidate(); 
    return true; 
} 

 

 

上面的CustomView你也可以在xml中引用只是你需要加包名

 

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: