本文介绍了巴顿和GLSurfaceView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的表现出一定的动画使用OpenGL一个GLSurfaceView。

I have a GLSurfaceView where I show some animations using OpenGL.

我现在想添加一个按钮,这个观点。这是如何实现的呢?

I now want to add a button to this view. How is this accomplished?

能把它不涉及XML布局做?

Can it be done without involving the xml layout?

推荐答案

您可以手动建立和增加欣赏到活动的内容视图。在这样做的setContentView在您GLSurfaceView或通过XML布局可以做这将在左上角添加在GLSurfaceView顶部的按钮以下后在活动的onCreate方法:

You can manually build and add Views to the content view of the Activity. In the onCreate method in your Activity after doing setContentView on your GLSurfaceView or through an XML layout you can do the following which will add a button on top of the GLSurfaceView in the upper left corner:

 Button b = new Button(this);
 b.setText("Hello World");
 this.addContentView(b,
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

如果您希望按钮在别处在屏幕上,你需要将它添加到布局,然后该布局添加到内容视图。为了有一个按钮,是你可以做以下的屏幕中心:

If you want the button to be somewhere else on screen you will need to add it to a layout and then add that layout to the content view. To have a button that is in the center of the screen you can do the following:

LinearLayout ll = new LinearLayout(this);
Button b = new Button(this);
b.setText("hello world");
ll.addView(b);
ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
this.addContentView(ll,
            new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

如果你想在屏幕底部的按钮,你可以使用Gravity.CENTER_VERTICAL等Gravity.BOTTOM代替。

If you want the button on the bottom of the screen you can use Gravity.BOTTOM instead of Gravity.CENTER_VERTICAL etc.

请确保您所呼叫的回报super.onTouch ......在你的触摸事件的方法,如果你的GLSurfaceView是拦截触摸,否则你的按钮将不会收到触摸事件。

Make sure you are calling return super.onTouch... in your touch event methods if your GLSurfaceView is intercepting touches or else your button will not receive touch events.

这篇关于巴顿和GLSurfaceView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 05:48