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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:25:09+00:00 2026-06-04T18:25:09+00:00

Currently I understand I can create a XML Layout and pass that to setContentView(…),

  • 0

Currently I understand I can create a XML Layout and pass that to setContentView(…), or I can pass a Customized view to setContentView(…).

But what if I want to combine the elements of both? Is it possible to use a layout first, then to programmatically add to the UI via java code?

For example: How could I create a view that uses an Asset background picture with an added loading widget on top?

ADDED INQUIRY: Right now and I think of a View and a Layout as two things for setContentView to display. But can a View hold a layout within it to be displayed?

  • 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-06-04T18:25:11+00:00Added an answer on June 4, 2026 at 6:25 pm

    Yes its possible to set an XML layout with setContentView(), and programmatically add more views/widget to that layout. Here’s a short example.

    main.xml

    <?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" 
        android:background="@drawable/background_image">
    
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Some text"/>
    
        <LinearLayout 
            android:id="@+id/custom_content_root"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
                android:orientation="vertical">
    
            <!-- This is where we will add views programmatically -->
        </LinearLayout>
    </LinearLayout>
    

    TestActivity.java

    public class TestActivity extends Activity {
    private LinearLayout mRoot;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // Set the layout
        setContentView(R.layout.main);
    
        // Get the Linearlayout we want to add new content to..
        mRoot = (LinearLayout) findViewById(R.id.custom_content_root);
    
        // Create a TextView for example
        TextView moreText = new TextView(this);
    
        // Set the layout parameters of the new textview.
        moreText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.WRAP_CONTENT));
    
        moreText.setText("More text :)");
    
        // Add the new textview to our existing layout
        mRoot.addView(moreText);
    }
    }
    

    The result is an activity with background_image.png as background, and two textviews with text 😉

    You can add any type of view (TextView, EditText, ImageView, Buttons etc) this way.

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

Sidebar

Related Questions

I'm learning regex, and I can't understand the grouping in Java. Currently my regex
really can't understand, how to build correctly project that uses boost.python. I've included boost_(python/thread/system)-mt.
The question says it all. I understand that VC11 is currently only in beta,
I've spent whole days with PHP's DOM functions but i can't understand how it
I (think I) understand that you can only retrieve the size of an array
I need to generate classes from xml that doesn't provide a schema. I understand
I am currently trying to understand the ray tracer developed by Kevin Beason (smallpt:
So I am currently using inline-block for my site. I understand it's still relatively
Do I understand correctly that CCLabelBMFont only loads the font texture once, no matter
This is just a quick question to understand correctly what happens when you create

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.