一、效果图
二、实现过程
首先自定义一个View,初始化各种画笔工具,方便后面画图形,通过监听onToutch方法来动态绘制矩形框。
主要实现代码如下:(MotionEvent event) {
(!isEnabled()) {
}
x = () event.getX()y = () event.getY()(event.getAction()) {
MotionEvent.:
= = = = = = = x= y(!= ) {
.onTouch()}
(isAreaContainPoint(xy)) {
= = invalidate()(!= ) {
.onConfirm()}
} (isAreaContainPoint(xy)) {
= = (!= ) {
.onCancel()= = = = = adjustMark()}
} (isAreaContainPoint(xy)) {
= = } (isAreaContainPoint(xy)) {
= = } (isAreaContainPoint(xy)) {
= = } (isAreaContainPoint(xy)) {
= = } (.contains(xy)) {
= } {
= = () event.getX()= () event.getY()= = }
MotionEvent.:
() {
}
adjustMark(xy)MotionEvent.:
= () {
}
adjustMark(xy)= .= .= .= .(.width() > .getWidth() * + * && .height() > .getHeight() * ) {
.set(- .getWidth() - - .getHeight() - - - ).set(- * .getWidth() - * - ScreenUtil.()- .getHeight() - - .getWidth() - * - ScreenUtil.()- )} (> getHeight() - .getHeight() * ) {
.set(- .getWidth() - - .getHeight() - - - ).set(- * .getWidth() - * - ScreenUtil.()- .getHeight() - - .getWidth() - * - ScreenUtil.()- )} {
.set(- .getWidth() - + - + .getHeight() + ).set(- * .getWidth() - * - ScreenUtil.()+ - .getWidth() - * - ScreenUtil.()+ .getHeight() + )}
(.
cancelAreaLeftMargin = Math.(.) + .= .+ cancelAreaLeftMargin.= .+ cancelAreaLeftMargin.= .+ cancelAreaLeftMargin.= .+ cancelAreaLeftMargin}
(!) {
(!= ) {
.onCancel()}
}
MotionEvent.:
= }
postInvalidate()}
三、项目结构图
三、说明
项目里面截图已经实时保存到了本地(目录:/sdcard/AShotPhoto),方便查看截图效果,不需要保存操作的可以在代码中注释。