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?
Can it be done without involving the xml layout?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
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:
If you want the button on the bottom of the screen you can use Gravity.BOTTOM instead of Gravity.CENTER_VERTICAL etc.
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.