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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:58:53+00:00 2026-06-05T23:58:53+00:00

XML Code: <GridLayout android:id=@+id/grid android:layout_width=fill_parent android:layout_height=fill_parent android:layout_above=@+id/step android:layout_alignParentLeft=true android:layout_alignParentRight=true android:layout_below=@+id/menu > </GridLayout> The above

  • 0

XML Code:

<GridLayout
    android:id="@+id/grid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/step"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/menu" >
</GridLayout>

The above code creates a grid to allow an easy layout for the buttons being created.

Java code:

GridLayout grid = (GridLayout)findViewById(R.id.grid);
grid.setColumnCount(10);
grid.setRowCount(10);
cells = new Button[100];
for (int i = 0; i < 100; i++) { 
    cells[i] = new Button(this);

    if (gen.nextInt(3) % radiofill == 0) //[0,3)
        cells[i].setBackgroundColor(Color.WHITE);
    else
        cells[i].setBackgroundColor(Color.BLACK);

    cells[i].setClickable(true);
    cells[i].setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
            v.setBackgroundColor(Color.BLACK);
        }
    });
    grid.addView(cells[i]); 
}

In this code 100 buttons are being created and added to an array that is eventually added to the GridLayout created in the XML.

All the buttons seem to be created, placed, and working as they are meant to but the buttons are so large they do not fit in the screen on the phone. How can I make it where the buttons fill the GridLayout fully without over or under flowing? In this instance 100 buttons are created but the program is designed to allow the creation of multiple types of perfect square numbers (4, 9, 16, 25, 36, 49) so the GridLayout needs to be flexible.

  • 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-05T23:58:55+00:00Added an answer on June 5, 2026 at 11:58 pm

    If you are using a LinearLayout you can

    <LinearLayout android:layout_height="wrap_content"
    android:layout_width="0dip"
    android:layout_weight="1" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my xml code is <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:layout_gravity=center_vertical android:lines=1 android:singleLine=true android:textColor=#ffffff android:focusable=true android:marqueeRepeatLimit=marquee_forever android:ellipsize=marquee
I wrote this XML code; <TableLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:layout_weight=20 > <TableRow android:layout_height=fill_parent android:layout_weight=10
Look at the XML code here please: <TableLayout android:id=@+id/tableLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:padding=10dip xmlns:android=http://schemas.android.com/apk/res/android> <TableRow
I am doing a preferenceScreen with this xml code: <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:orderingFromXml=true> <PreferenceCategory android:key=pref1
My xml code: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/RelativeLayout1 android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical > <RelativeLayout
My xml code is here, <?xml version=1.0 encoding=utf-8?><RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:id=@+id/mainlayout > <LinearLayout
This is xml code: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/mainLayout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical> </LinearLayout>
here is my xml code <autoLoad value=true/> <autoPlay value=false/> <playContinuously value=true/> <jumpToNextCategory value=false/> <loop
My XML code is : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> <ScrollView
MY XMl code looks like : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=wrap_content>

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.