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 7168963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:53:20+00:00 2026-05-28T14:53:20+00:00

I’m attemping to add a new LinearLayout defined by xml on top of my

  • 0

I’m attemping to add a new LinearLayout defined by xml on top of my opengl view.

I have this working by using pure java:

public class VortexView extends GLSurfaceView {
 public boolean onTouchEvent(final MotionEvent event) {
        show_something();
 }

void show_something()
{
  //context is the main activity object that gets passed into this
  LinearLayout ll = new LinearLayout(context);
  b = new Button(context);
  b.setText("hello world 1");
  ll.addView(b);
  ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
  context.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
}

However I want to be able to do this:

LinearLayout ll = (LinearLayout)findViewById(R.layout.main);
context.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT));

My xml is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:orientation="vertical" >
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="kill"
    />
</LinearLayout>

Everytime I do this though the app crashes. Any ideas?

  • 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-28T14:53:21+00:00Added an answer on May 28, 2026 at 2:53 pm

    Is it possible you are making a mess there?
    Let’s try it in a different way, create a GLSurfaceView at the background, and add the LinearLayout on top of it.

    main.xml file:

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/relativeLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
    
            <path.to.vortex.VortexView
                android:id="@+id/vortexView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true" >
            </path.to.vortex.VortexView>
    
     <LinearLayout
                android:id="@+id/linearLayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
       </LinearLayout>
    </RelativeLayout>
    

    in your VortexView class add constructors and initilazation

      public class VortexView extends GLSurfaceView {
    
        public VortexView (Context context)
        {
            super(context);
            init(context);
        }
    
        public VortexView (Context context, AttributeSet atts)
        {
            super(context, atts);
            init(context);
        }
    
        public VortexView (Context context, AttributeSet atts, int defStyle)
        {
            super(context, atts, defStyle);
            init(context);
        }
    
        public void init(context)
        {
            //do whatever you need to init your view here...
        }
    }
    

    In your activity you’ll need to setContentView() on your main.xml:

    public class VortexActivity extends Activity
    {
        Context mContext;
        VortexView mVortexView;
        RelativeLayout relativeLayout;
    
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            mContext = getApplicationContext();
            setContentView(R.layout.main);
    
            mVortexView = (VortexView) findViewById(R.id.vortexView);
            mRelativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        }
    }
    

    now you are free to do whatever you wish with your layouts, and since the VortexView was declared in the xml before the LinearLayout it will be in it’s background.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article

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.