Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1054711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:26:55+00:00 2026-05-16T17:26:55+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:26:56+00:00Added an answer on May 16, 2026 at 5:26 pm

    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));
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom view (which extends GLSurfaceView) I'm trying to use in my
have a wierd issue. for the life of me can't trace this back (its
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a very basic Activity at the moment. It creates a GLSurfaceView and
I have a button class thats created from within the onSurfaceCreated method in my
I just want to ask a simple question related the GLSurfaceView and drawn objects
Have same challenge as this guy: How to copy dependencies to gae war/WEB-INF/lib Applying
Have you ever seen any of there error messages? -- SQL Server 2000 Could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.