Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
samlss committed Jan 3, 2019
1 parent d72a57a commit 399e6d9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lighter/src/main/java/me/samlss/lighter/view/LighterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private LayoutParams calculateLayoutParams(int width, int height, LighterParamet
return layoutParams;
}

boolean alignRight = false;
switch (lighterParameter.getTipViewRelativeDirection()){
default:
case Direction.LEFT:
Expand All @@ -182,6 +183,7 @@ private LayoutParams calculateLayoutParams(int width, int height, LighterParamet

case Direction.TOP:
if (highlightedViewRect.left > width / 2){ //on the right
alignRight = true;
layoutParams.rightMargin = (int) (width - highlightedViewRect.right + marginOffset.getRightOffset());
}else{ //on the left
layoutParams.leftMargin = (int) (highlightedViewRect.left + marginOffset.getLeftOffset());
Expand All @@ -191,6 +193,7 @@ private LayoutParams calculateLayoutParams(int width, int height, LighterParamet

case Direction.BOTTOM:
if (highlightedViewRect.left > width / 2){ //on the right
alignRight = true;
layoutParams.rightMargin = (int) (width - highlightedViewRect.right + marginOffset.getRightOffset());
}else{ //on the left
layoutParams.leftMargin = (int) (highlightedViewRect.left + marginOffset.getLeftOffset());
Expand All @@ -199,7 +202,8 @@ private LayoutParams calculateLayoutParams(int width, int height, LighterParamet
break;
}

if(layoutParams.rightMargin != 0){
if(layoutParams.rightMargin != 0
|| alignRight){
layoutParams.gravity = Gravity.RIGHT;
}else {
layoutParams.gravity = Gravity.LEFT;
Expand Down Expand Up @@ -231,8 +235,7 @@ protected void onDraw(Canvas canvas) {
mBgColor = ViewUtils.DEFAULT_HIGHLIGHT_VIEW_BG_COLOR;
}

canvas.save();

// canvas.save();
//firstly, clip the rects of all the highlighted views.
if (mLighterParameterList != null && !mLighterParameterList.isEmpty()) {
for (LighterParameter lighterParameter : mLighterParameterList) {
Expand Down Expand Up @@ -262,7 +265,7 @@ protected void onDraw(Canvas canvas) {
}
}

canvas.restore();
// canvas.restore();
}

public void setInitHeight(int initHeight) {
Expand Down

0 comments on commit 399e6d9

Please # to comment.