setGesture() 在屏幕外显示手势:Android
我正在开发一个 Android 应用程序,我需要在其中向用户显示保存的手势。我尝试使用 GestureOverlayView 对象的 setGesture() 函数来执行此操作,但它在屏幕外显示手势。在 Android 模拟器 2.1 中,屏幕的左上角仅可见一小部分。 这是我使用过的代码..
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();
}
“savegesture.xml”中定义的android GestureOverlayView如下:-
<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 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....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然这是一个 3 年前的问题,但我仍然会添加一个答案。
该手势出现在
GestureOverlayView
之外,因为它是在onCreate
中设置的。必须在计算布局尺寸后设置它。ViewTreeObserver
可用于了解何时测量了布局。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 inonCreate
. It must be set after the layout measurements have been computed.ViewTreeObserver
can be used to know when the layout has been measured.尽管这是一个 5 年前的问题,我仍然会添加一个答案,因为与此相比,批准的答案效率较低:
Use
view.post()
toexecute code after the view has was returned 。Altough this is a 5 year old question, I'll still add an answer, because the approved answer is inefficient in comparison to this:
Use
view.post()
to execute code after the view has been loaded.