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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:41:48+00:00 2026-05-23T10:41:48+00:00

I have created an array of buttons for my app. Now I am not

  • 0

I have created an array of buttons for my app. Now I am not able to manage the layout of these array of buttons. As a result of this, whenever I add image or change width of the buttons it’s going out of the horizontal screen of the device. So is there any way to manage these Array of buttons so that they can fit in any screen size.
Here is my code:

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
    android:id="@+id/liVLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    </LinearLayout>

    <LinearLayout
    android:id="@+id/liVLayout1"
    android:orientation="vertical"
    android:layout_below="@+id/liVLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:text="All Contacts" 
        android:id="@+id/textView1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textColor="@android:color/black"
        android:background="#808080">
    </TextView> 
    </LinearLayout>
</RelativeLayout>

Java:

public class CalenderForm extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    createCalender();
}
public void createCalender()
{
    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams
    (
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT
    );  
    LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
    LinearLayout rowLayout=null;
    Button[][] buttons = new Button[6][7]; 
    int count=43;
    for (int i = 0; i<6; i++) 
    {
        if(count%7==1)
        {
            rowLayout = new LinearLayout(this);
            layoutVertical.addView(rowLayout,p);
            count=count-7;
        }
        for(int j=0;j<7;j++)
        {
            buttons[i][j]=new Button(this);
            buttons[i][j].setBackgroundResource(R.drawable.icon); 
            rowLayout.addView(buttons[i][j], p);
        }
    }
}

}

Snapshot before inserting image:

enter image description here

Snapshot before inserting image:

enter image description here

  • 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-23T10:41:49+00:00Added an answer on May 23, 2026 at 10:41 am

    just replace this code.use weightsum property of linear and layout_weight of buttons.

    package com.android.manager;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.Button;
    import android.widget.LinearLayout;
    
    public class MainActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            createCalender();
        }
        public void createCalender()
        {  
            LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
            LinearLayout rowLayout=null;
            Button[][] buttons = new Button[6][7]; 
            int count=43;
            **LayoutParams param = new LinearLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT,1);**
    
            for (int i = 0; i<6; i++) 
            {
                if(count%7==1)
                {
                    rowLayout = new LinearLayout(this);
                    **rowLayout.setWeightSum(7);**
                    **layoutVertical.addView(rowLayout,param);**
                    count=count-7;
                }
                for(int j=0;j<7;j++)
                {
                    buttons[i][j]=new Button(this);
                    buttons[i][j].setBackgroundResource(R.drawable.icon);
                    **rowLayout.addView(buttons[i][j],param);**
                }
            }
        }
    
    }
    

    enter image description here

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

Sidebar

Related Questions

I have created an array of buttons consisting of 6 rows and 7 columns.Now
I have created 4 buttons via Interface Builder. I have an array which has
I have created an array in php that prints this Array ( [mark] =>
I have an array created with this code: var widthRange = new Array(); widthRange[46]
Hi I have created a setDecorator() which is something like this: $timeSu->setDecorators(array('ViewHelper', 'Description', 'Errors',
I am creating buttons dynamically for a user-based app. Now I have to tell
i have created a tableview default app with xcode. But: in AppDelegate a add
I have created a Facebook Canvas App. This canvas app is essentially an image
i have created Array of Linkbutton and when user click on link button it
I have created an array square(40) as picturebox. I have to assign 40 picture

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.