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

  • SEARCH
  • Home
  • 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 8545701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:51:13+00:00 2026-06-11T12:51:13+00:00

I want to create a XML layout dynamically but I had a question on

  • 0

I want to create a XML layout dynamically but I had a question on doing so.

Say I have something like this (Looking at the layout from the “Outline” perspective):

-ScrollView

—Linear Layout(Vertical) (LL1)

——-Linear Layout(Horizontal) (LL2)

———–Image View (IV1)

———–Linear Layout(Vertical) (LL3)

—————TextView

—————TextView

So my question here is would I start with the most inner Layout (LL3) and add the 2 TextViews and then branch upwards (to LL2 then LL1 then ScrollView) with adding to the other views & layouts?

  • 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-11T12:51:14+00:00Added an answer on June 11, 2026 at 12:51 pm

    I believe you can do this several ways. I’ve not tried creating an entire hierarchy like this dynamically, but I’ve added buttons, radio-buttons, text-views and other Views this way several times. In those cases, I’ve just added new ones to the ones that already exist using AddView().

    I think the easiest way is to just create it “top down”, i.e. create the ScrollView first and add any settings, then add the other views to it downwards. I would typically do something like this:

    // Call other methods to create the views first:
    ScrollView myScrollView = createMainScrollView();
    LinearLayout myHorizontalLayout = createLinearLayoutForAbc();
    LinearLayout myOtherLayout = createLinearLayoutForXyz();
    TextView myFirstTxt = (...)
    (..etc..)
    

    Now populate them in the right way:

    myScrollView.addView(myHorizontalLayout);
    myHorizontalLayout.addView(myOtherLayout);
    (..etc..)
    

    Note:
    I do believe this should work, but I can not guarantee it; if the reference to an inner view is no longer correct after having been added to an outer view (Eg. myHorizontalLayout is no longer a valid ref to the actual view under myScrollView), you might not be able to add children to that inner view. Not sure about this, though.

    (If so, you might try to fetch a new, correct reference using findViewByName() after adding each view, but I don’t think that would be an optimal solution).

    I would try the first way first – at least make a proof of concept, to see that you can add view in a hierarchy at least three levels deep. That should give you your answer. If it does not work, I suppose I would try adding them in the opposite order, as you suggest in your question, just to see if that works (maybe just switch the order in my second code block?).

    Sorry for the imprecise answer, hope it is of some help anyway.

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

Sidebar

Related Questions

I want to create a layout like below.. This is the XML i have
I want to create a neat two-columns input form like this: My xml layout
I have the xml layout, and I want to create View from it -
I have to create the Layout (in xml or in java) as like Below
I want to create a layout something like shown in image below can anyone
I want to create a Button otherthan creating it from xml layout.i want to
I want to create a XML file in csharp like the below format pls
I have an XML file (on the left) and I want to create multiple
i want to save an .XML file that i create with php dom, but
I want to write application where I create layout in the code (without xml-layout

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.