Making A Tutorial (coach Mark) Overlay. Need Help Moving A View Based On The Position Of Another
Solution 1:
This is what you should do:
button1.getViewTreeObserver().addOnPreDrawListener(newOnPreDrawListener() {
publicbooleanonPreDraw() {
button1.getViewTreeObserver().removeOnPreDrawListener(this);
x = button1.getTop();
showOverLay();
returntrue;
}
});
Actually when you call x = button1.getTop();
in onCreate()
the Button view is not yet drawn and measured, hence the value of getTop
is 0. Try this out.
Solution 2:
Don't use Dialog for such overlays, they may require a separate window. Just make you activity such that it can display a View on top of everything i.e. its content view is a FrameLayout
to which you can easily add and remove any View
object.
Then, you can find any other view object's global rectangle in window by using getGlobalVisibleRect()
. Next, you align your help content to any side of this rectangle.
Solution 3:
You should make your UI drawings after the layout completes its drawing. You can do this by attaching a Runnable
interface on the layout's drawing thread. When you're calculating margins or paddings, you should do this after the view is created. Please see: onFinishInflate();
button1.post(newRunnable() {
x = button1.getTop();
showOverLayout();
});
Solution 4:
Add this in your showOverlay() method:
TextView textView = (TextView) dialog.findViewById(R.id.textView1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, x);
textView.setLayoutParams(params);
and remove this from your xml file:
android:layout_centerVertical="true"
Post a Comment for "Making A Tutorial (coach Mark) Overlay. Need Help Moving A View Based On The Position Of Another"