I am developing an android app in which I need to display the saved gesture to the user. I have tried doing it using the GestureOverlayView object's setGesture() function but it displays the gesture well outside the screen. Only small portion is visible in the left top corner of the screen in the Android emulator 2.1. Here is the code that I have used..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.savegesture);
gestureoverlay = (GestureOverlayView) findViewById(R.id.gestures_overlay2);
mOldGesture = (Gesture) getIntent().getExtras().get("gesture");
mDoneButton = findViewById(R.id.done);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
gestureoverlay.setLayoutParams(new FrameLayout.LayoutParams(dm.widthPixels,dm.heightPixels,0x50));
gestureoverlay.setGesture(mOldGesture);
gestureoverlay.invalidate();
}
The android GestureOverlayView defined in "savegesture.xml" is as follows:-
<android.gesture.GestureOverlayView android:scaleType="center" android:layout_gravity="center"
android:id="@+id/gestures_overlay2" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gestureStrokeType="multiple" />
I don't know what the problem is, but it won't show the gesture ON the screen....
Although this is a 3 year old question, I'll still add an answer.
The gesture appears outside the GestureOverlayView
because it's been set in onCreate
. It must be set after the layout measurements have been computed.
ViewTreeObserver
can be used to know when the layout has been measured.
ViewTreeObserver vto = gestureoverlay.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
gestureoverlay.getViewTreeObserver().removeGlobalOnLayoutListener(this);
gestureoverlay.setGesture(mOldGesture);
}
});