From 171233136b3118e429fa753e42f2c018e7289f11 Mon Sep 17 00:00:00 2001 From: yilylong Date: Mon, 27 Nov 2017 17:20:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=AE=AD=E5=A4=B4=E6=98=BE=E7=A4=BA=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zhl/userguideview/UserGuideView.java | 60 +++++++++++++------ .../userguideview/UserGuideTestActivity.java | 1 + 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/Userguidelibrary/src/main/java/com/zhl/userguideview/UserGuideView.java b/Userguidelibrary/src/main/java/com/zhl/userguideview/UserGuideView.java index 719dc6f..99666e8 100644 --- a/Userguidelibrary/src/main/java/com/zhl/userguideview/UserGuideView.java +++ b/Userguidelibrary/src/main/java/com/zhl/userguideview/UserGuideView.java @@ -50,6 +50,7 @@ public class UserGuideView extends View { private int statusBarHeight = 0;// 状态栏高度 private ArrayList targetViews; private Rect tipViewHitRect; + private boolean showArrow = true;// 是否显示指示箭头 public UserGuideView(Context context) { this(context, null); @@ -267,60 +268,75 @@ protected void onDraw(Canvas canvas) { if (bottom < screenH / 2 || (screenH / 2 - top > bottom - screenH / 2)) {// top int jtTop = getUpJtTop(bottom, vHeight); if (right < screenW / 2 || (screenW / 2 - left > right - screenW / 2)) {//left - canvas.drawBitmap(jtUpLeft, left + vWidth / 2, jtTop, null); + if(showArrow){ + canvas.drawBitmap(jtUpLeft, left + vWidth / 2, jtTop, null); + } + int tipTop = showArrow?jtTop + jtUpLeft.getHeight():jtTop; if (tipBitmap != null) { - canvas.drawBitmap(tipBitmap, left + vWidth / 2, jtTop + jtUpLeft.getHeight(), null); - tipViewHitRect = new Rect(left + vWidth / 2,jtTop + jtUpLeft.getHeight(),left + vWidth / 2+tipBitmap.getWidth(),jtTop + jtUpLeft.getHeight()+tipBitmap.getHeight()); + canvas.drawBitmap(tipBitmap, left + vWidth / 2, tipTop, null); + tipViewHitRect = new Rect(left + vWidth / 2,tipTop,left + vWidth / 2+tipBitmap.getWidth(),tipTop+tipBitmap.getHeight()); } }else if (screenW / 2 - 10 <= right - offestMargin - vWidth / 2 && right - offestMargin - vWidth / 2 <= screenW / 2 + 10){// center - canvas.drawBitmap(jtUpCenter, left + offestMargin + vWidth / 2 - jtUpCenter.getWidth() / 2, jtTop, null); + if(showArrow){ + canvas.drawBitmap(jtUpCenter, left + offestMargin + vWidth / 2 - jtUpCenter.getWidth() / 2, jtTop, null); + } if(tipBitmap!=null){ int tipLeft = left + offestMargin + vWidth / 2 - tipBitmap.getWidth() / 2; - int tipTop = jtTop + jtUpCenter.getHeight(); + int tipTop = showArrow?jtTop + jtUpCenter.getHeight():jtTop; canvas.drawBitmap(tipBitmap,tipLeft ,tipTop , null); tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),tipTop+tipBitmap.getHeight()); } } else { - canvas.drawBitmap(jtUpRight, left + vWidth / 2 - 100 - margin, jtTop, null); + if(showArrow){ + canvas.drawBitmap(jtUpRight, left + vWidth / 2 - 100 - margin, jtTop, null); + } if (tipBitmap != null) { int tipLeft = left + vWidth / 2 - 100 - tipBitmap.getWidth() / 2; + int tipTop = showArrow?jtTop + jtUpRight.getHeight():jtTop; // 如果提示图片超出屏幕右边界 if (tipLeft + tipBitmap.getWidth() > screenW) { tipLeft = screenW - tipBitmap.getWidth() - borderWitdh; } - canvas.drawBitmap(tipBitmap, tipLeft, jtTop + jtUpRight.getHeight(), null); - tipViewHitRect = new Rect(tipLeft,jtTop + jtUpLeft.getHeight(),tipLeft+tipBitmap.getWidth(),jtTop + jtUpLeft.getHeight()+tipBitmap.getHeight()); + canvas.drawBitmap(tipBitmap, tipLeft, tipTop, null); + tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),tipTop+tipBitmap.getHeight()); } } } else {// bottom int jtTop = getDownJTtop(jtDownLeft, top, vHeight); int jtDownCenterTop = getDownJTtop(jtDownCenter, top, vHeight); if (right < screenW / 2 || (screenW / 2 - left > right - screenW / 2)) {// 左 - canvas.drawBitmap(jtDownLeft, left + vWidth / 2, jtTop, null); + if(showArrow){ + canvas.drawBitmap(jtDownLeft, left + vWidth / 2, jtTop, null); + } if (tipBitmap != null) { int tipLeft = left + vWidth / 2; - int tipTop = jtTop - tipBitmap.getHeight(); + int tipTop = showArrow?jtTop - tipBitmap.getHeight():top-tipBitmap.getHeight()-margin; canvas.drawBitmap(tipBitmap, tipLeft, tipTop, null); - tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),jtTop); + tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),showArrow?jtTop:top); } } else if (screenW / 2 - 10 <= right - offestMargin - vWidth / 2 && right - offestMargin - vWidth / 2 <= screenW / 2 + 10) {// 如果基本在中间(screenW/2-10<=target的中线<=screenW/2+10) - canvas.drawBitmap(jtDownCenter, left + offestMargin + vWidth / 2 - jtDownCenter.getWidth() / 2, jtDownCenterTop, null); + if(showArrow){ + canvas.drawBitmap(jtDownCenter, left + offestMargin + vWidth / 2 - jtDownCenter.getWidth() / 2, jtDownCenterTop, null); + } if (tipBitmap != null) { int tipLeft = left + offestMargin + vWidth / 2 - tipBitmap.getWidth() / 2; - int tipTop = jtDownCenterTop - tipBitmap.getHeight(); + int tipTop = showArrow?jtDownCenterTop - tipBitmap.getHeight():top-tipBitmap.getHeight()-margin; canvas.drawBitmap(tipBitmap, tipLeft, tipTop, null); - tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),jtDownCenterTop); + tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),showArrow?jtDownCenterTop:top); } } else {// 右 - canvas.drawBitmap(jtDownRight, left + vWidth / 2 - 100 - margin, jtTop, null); + if(showArrow){ + canvas.drawBitmap(jtDownRight, left + vWidth / 2 - 100 - margin, jtTop, null); + } if (tipBitmap != null) { int tipLeft = left + vWidth / 2 - 100 - tipBitmap.getWidth() / 2 - margin; // 如果提示图片超出屏幕右边界 if (tipLeft + tipBitmap.getWidth() > screenW) { tipLeft = screenW - tipBitmap.getWidth() - borderWitdh; } - canvas.drawBitmap(tipBitmap, tipLeft, jtTop - tipBitmap.getHeight(), null); - tipViewHitRect = new Rect(tipLeft,jtTop - tipBitmap.getHeight(),tipLeft+tipBitmap.getWidth(),jtTop); + int tipTop = showArrow?jtTop - tipBitmap.getHeight():top-tipBitmap.getHeight()-margin; + canvas.drawBitmap(tipBitmap, tipLeft,tipTop , null); + tipViewHitRect = new Rect(tipLeft,tipTop,tipLeft+tipBitmap.getWidth(),showArrow?jtTop:top); } } } @@ -331,7 +347,7 @@ protected void onDraw(Canvas canvas) { private int getUpJtTop(int targetBottom, int targetHeight) { int jtTop = 0; if (highLightStyle == VIEWSTYLE_CIRCLE) { - jtTop = targetBottom + (radius - targetHeight / 2) + -margin + offestMargin; + jtTop = targetBottom + (radius - targetHeight / 2) + margin + offestMargin; } else { jtTop = targetBottom + margin + offestMargin; } @@ -485,6 +501,14 @@ public int getOffestMargin() { return offestMargin; } + public boolean isShowArrow() { + return showArrow; + } + + public void setShowArrow(boolean showArrow) { + this.showArrow = showArrow; + } + /** * 光圈放大偏移值 * diff --git a/app/src/main/java/com/zhl/userguideview/UserGuideTestActivity.java b/app/src/main/java/com/zhl/userguideview/UserGuideTestActivity.java index c8160a6..dcded48 100644 --- a/app/src/main/java/com/zhl/userguideview/UserGuideTestActivity.java +++ b/app/src/main/java/com/zhl/userguideview/UserGuideTestActivity.java @@ -30,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.layout_userguide); guideView = (UserGuideView) findViewById(R.id.guideView); guideView.setTouchOutsideDismiss(false); +// guideView.setShowArrow(false); tipTextView = LayoutInflater.from(this).inflate(R.layout.custom_tipview,null); // icon = (ImageView) findViewById(R.id.icon); // guideView.setHighLightView(icon);