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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:36:12+00:00 2026-06-09T00:36:12+00:00

I want to create a layout dynamically in android which consist some buttons. But

  • 0

I want to create a layout dynamically in android which consist some buttons. But I am unable to find any way to dynamically create this layout.

Here is my layout :

Dynamic Layout

I want to put buttons into next line after they completely filled in the width of device. Total number of buttons can be varied.
Is there any way to do this dynamically?

UPDATE :
As per your suggestions I’m using this code :

private void addQuestionPallete() {
        int tempBtn = 30;
        LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 0.1f);
        LayoutParams param2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f);

        linearContent.setWeightSum(1f);
        linearContent.setOrientation(LinearLayout.VERTICAL);
        btnQuestionPalete = new Button[10];

        for (int j = 0; j < tempBtn / 10; j++) {
            linearQuestionPalettesRow = new LinearLayout(mContext);
            linearQuestionPalettesRow.setOrientation(LinearLayout.HORIZONTAL);
            linearQuestionPalettesRow.setLayoutParams(param2);
            for (int i = 0; i < 10; i++) {
                btnQuestionPalete[i] = new Button(mContext);
                btnQuestionPalete[i].setLayoutParams(param);
                btnQuestionPalete[i].setTextColor(Color.BLACK);
                btnQuestionPalete[i].setText("5");
                btnQuestionPalete[i].setId(fChexkBoxID++);
                linearQuestionPalettesRow.addView(btnQuestionPalete[i]);
            }
        }
        linearContent.addView(linearQuestionPalettesRow);
    }

but its only showing single row of buttons. Where I’m doing wrong?

UPDATE :

OK I have solved my problem. I was adding layout out of for loop. thus the layout is adding only one time.

  • 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-09T00:36:14+00:00Added an answer on June 9, 2026 at 12:36 am
    • Add a Horizontal Linear Layout in a Vertical Linear Layout.
    • Set the “weight sum” of the Horizontal Linear Layout to 1.
    • Now before adding the buttons, set each button’s weight to 0.1
    • Keep a counter for the numbers of buttons added starting from 1 and when it reaches 10, add another horizontal Linear Layout.

    You can change the weight of the buttons as you like, making them larger or smaller and then adjust your counter to behave accordingly.

    For e.g., if you decide to assign weight = 0.2 to each button, then your counter should count till 5 (1/0.2 = 5). You can also set the weight as 0.05 or 0.025 etc. depending upon the number of buttons you want in each row.

    This way you need not worry about the different screen sizes because the weight property will adjust the views in any screen size.

    • 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 for an Android app that has a numeric
I want to create a layout in such a way that on top edittext
I'm having an issue with my android application. I want to dynamically create 4
I want to create one button/layout object dynamically from the object that exist on
I'm trying to create a buttons dynamically and add them to table layout panel
I want to create layout like this on facebook app. Тo appear with effect
I want to create layout programmatically in different class which is not an activity
I want to create a layout in which two bars , one at top
I'm facing an issue on my android application. I want to dynamically create TableRow
I want to create a grid layout for a webpage. It should consist of

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.