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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:29:10+00:00 2026-05-29T09:29:10+00:00

I am facing a scenario, where my main.xml has its main hierarchy written in

  • 0

I am facing a scenario, where my main.xml has its main hierarchy written in XML but, the main data is coming from the server, so I need to compose the layout in runtime.

Please, take a look on this screenshot to better understand my scenario.

I shall have a Scroll View and then right under it, a Linear Layout. I retrieve this layout in my java class and create a new linear layout , so that I can create the new TextViews and Buttons like I draw inside LinearLayout 2. The end result is far from I expected and I honestly am not sure how I can accomplish this.

The code for is:

LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayoutOffers); //this is the LinearLayout2 in SS

    //Creating the container that will have one business.
    LinearLayout containerMain = new LinearLayout(this);
    containerMain.setOrientation(LinearLayout.VERTICAL);
    containerMain.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));  
    containerMain.setGravity(Gravity.CENTER); 

    LinearLayout container1 = new LinearLayout(this);
    container1.setOrientation(LinearLayout.HORIZONTAL);
    container1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));  
    container1.setGravity(Gravity.CENTER);
    container1.setWeightSum(2);

    LinearLayout container2 = new LinearLayout(this);
    container2.setOrientation(LinearLayout.HORIZONTAL);
    container2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));  
    container2.setGravity(Gravity.CENTER); 
    container2.setWeightSum(1);

    LinearLayout container3 = new LinearLayout(this);
    container3.setOrientation(LinearLayout.HORIZONTAL);
    container3.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));  
    container3.setGravity(Gravity.CENTER);
    container3.setWeightSum(1);

    TextView offerTitle = new TextView(this);
    offerTitle.setText(pOfferTitle);  
    offerTitle.setTextSize(14);
    //offerTitle.setPadding(10, 0, 10, 0);
    offerTitle.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));

    Button redeemButton = new Button(this);
    redeemButton.setText("Usar");
    redeemButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
    //redeemButton.setPadding(10, 0, 10, 0);
    redeemButton.setTextSize(14);

    container1.addView(offerTitle);
    container1.addView(redeemButton);

    TextView mAddress = new TextView(this);
    mAddress.setText(pAddress);  
    mAddress.setTextSize(14);
    //mAddress.setPadding(10, 0, 10, 0);
    mAddress.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));

    container2.addView(mAddress);

    TextView expiryDate = new TextView(this);
    expiryDate.setText(pExpiryDate);  
    expiryDate.setTextSize(14);
    //expiryDate.setPadding(10, 0, 10, 0);
    offerTitle.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.6f));

    Button detailsButton = new Button(this);
    detailsButton.setText("Detalhes");
    detailsButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.4f));
    //detailsButton.setPadding(30, 0, 0, 0);
    detailsButton.setTextSize(14);

    container3.addView(expiryDate);
    container3.addView(detailsButton);

    containerMain.addView(container1);
    containerMain.addView(container2);
    containerMain.addView(container3);

    ll.addView(containerMain);

Thanks for your time!
Felipe

  • 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-29T09:29:11+00:00Added an answer on May 29, 2026 at 9:29 am

    I think a far better way would be to use a ListView.
    There you can define every row like you want. Also you can add or remove lines at runtime.
    A ScrollView collapses easily when you want to add elements to it on runtime.

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

Sidebar

Related Questions

The current issue im facing is comes from the following scenario. I have a
Facing a problem, it seems my data stored in SQL Server does not stored
Scenario: I have configured SQOOP on my PC. But I am facing some problem
I am facing a scenario here. I have a main class which initializes a
I am facing a very regular scenario. I have an NSArray which has object
I'm working on a JMS application. I'm facing a scenario where I need to
I'm facing a dilemma (!). In a first scenario, I implemented a solution that
Facing some issue in Talend Admin Console, the jobs that are running from IDE
Im facing one problem in streaming data capture for reading the broadcast data during
I have a MainFlow.xml which calls a SubFlow.xml and while doing so, the main

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.