Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.co.deanwild.materialshowcaseview.target;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.View;
Expand All @@ -22,11 +24,23 @@ public ViewTarget(int viewId, Activity activity) {
public Point getPoint() {
int[] location = new int[2];
mView.getLocationInWindow(location);
int x = location[0] + mView.getWidth() / 2;
int y = location[1] + mView.getHeight() / 2;
View decor = getActivity(mView).getWindow().getDecorView();
int x = location[0] - decor.getPaddingLeft() + mView.getWidth() / 2;
int y = location[1] - decor.getPaddingTop() + mView.getHeight() / 2;
return new Point(x, y);
}

private Activity getActivity(View view) {
Context context = view.getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity)context;
}
context = ((ContextWrapper)context).getBaseContext();
}
return null;
}

@Override
public Rect getBounds() {
int[] location = new int[2];
Expand Down