Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed Jul 25, 2021
1 parent 14a15de commit 811e1dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
19 changes: 17 additions & 2 deletions anylayer/src/main/java/per/goweii/anylayer/DecorLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;

import androidx.annotation.CallSuper;
Expand Down Expand Up @@ -214,13 +215,27 @@ protected final void setViewMarginTo(@NonNull View view, @NonNull Rect margin) {

@NonNull
protected final Rect getDecorPadding() {
Utils.getViewPadding(getViewHolder().getDecorChild(), mDecorPadding);
mDecorPadding.setEmpty();
Utils.getViewPadding(getViewHolder().getActivityContent(), mDecorPadding);
return mDecorPadding;
}

@NonNull
protected final Rect getDecorMargin() {
Utils.getViewMargin(getViewHolder().getDecorChild(), mDecorMargin);
mDecorMargin.setEmpty();
ViewGroup viewGroup = getViewHolder().getActivityContent();
while (true) {
Utils.getViewMargin(viewGroup, mDecorMargin);
ViewParent viewParent = viewGroup.getParent();
if (!(viewParent instanceof ViewGroup)) {
break;
}
viewGroup = (ViewGroup) viewParent;
Utils.getViewPadding(viewGroup, mDecorMargin);
if (viewGroup == getViewHolder().getDecor()) {
break;
}
}
return mDecorMargin;
}

Expand Down
18 changes: 8 additions & 10 deletions anylayer/src/main/java/per/goweii/anylayer/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,19 @@ public static void getViewSize(@NonNull final View view, @NonNull Runnable runna
}

public static void getViewPadding(@NonNull View view, @NonNull Rect rect) {
rect.setEmpty();
rect.left = view.getPaddingLeft();
rect.top = view.getPaddingTop();
rect.right = view.getPaddingRight();
rect.bottom = view.getPaddingBottom();
rect.left += view.getPaddingLeft();
rect.top += view.getPaddingTop();
rect.right += view.getPaddingRight();
rect.bottom += view.getPaddingBottom();
}

public static void getViewMargin(@NonNull View view, @NonNull Rect rect) {
rect.setEmpty();
if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) return;
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
rect.left = params.leftMargin;
rect.top = params.topMargin;
rect.right = params.rightMargin;
rect.bottom = params.bottomMargin;
rect.left += params.leftMargin;
rect.top += params.topMargin;
rect.right += params.rightMargin;
rect.bottom += params.bottomMargin;
}

public static int getViewMarginLeft(@NonNull View view) {
Expand Down

0 comments on commit 811e1dd

Please sign in to comment.