/**
* 不规则"图形按钮控件"
*
*/
public class TrapezoidImageButton extends ImageButton {
public TrapezoidImageButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public TrapezoidImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TrapezoidImageButton(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isTouchPointInView(event.getX(),event.getY())||
event.getAction() != MotionEvent.ACTION_DOWN){
return super.onTouchEvent(event);
}else{
return false;
}
}
protected boolean isTouchPointInView(float localX, float localY){
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
draw(canvas);
int x = (int)localX;
int y = (int)localY;
if (x < 0 || x >= getWidth())
return false;
if (y < 0 || y >= getHeight())
return false;
int pixel = bitmap.getPixel(x,y);
if ((pixel&0xff000000) != 0){ //点在非透明区
return true;
}else{
return false;
}
}
}
不规则图形按钮非透明区的点击
原创mb63e0703549da8 博主文章分类:android基础知识 ©著作权
©著作权归作者所有:来自51CTO博客作者mb63e0703549da8的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:android 无权限 伪造短信
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【CAD建模号】学习笔记(三):图形绘制区1
本期学习笔记介绍【CAD建模号】中图形绘制区的二维工具、面建模、实体工具和文本工具。
角点 二维 图形绘制 CAD建模号 模宗 -
Odoo中防止用户同一时间多次点击同一按钮触发函数
odoo防止用户重复快速点击按钮
ide xml javascript odoo -
有趣的CSS - 多彩变化的按钮
用css实现一个五彩斑斓的变化按钮。
css html 按钮 动画 动效 -
flink面试题2024
目录一、基础概念二、JobManager启动源码分析2.1、启动流程概述2.2、启动流程源码分析2.2.1 主节点准备工作分析2.2.2 主节点启动过程分析一、基础概念 在开始分析Flink JobManager启动之前流程之前,我们需要了解一些重要的概念。
flink面试题2024 java flink flink源码 初始化 -
C86 3250 是什么架构
所谓的32位、64位CPU指的是CPU的算术逻辑单元通用寄存器的位数。 Intel公司的80386是一个里程碑式的产品,之后的486、Pentium、Pentium II虽然在性能上有不小的改进,但都属于同一种体系结构,统称为i386结构。 &nbs
C86 3250 是什么架构 descriptor 数据结构 table 产品