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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:39:50+00:00 2026-06-09T08:39:50+00:00

The Android Developers Blog post introducing GridLayout shows this diagram of how spans impact

  • 0

The Android Developers Blog post introducing GridLayout shows this diagram of how spans impact automatic index allocation:

automatic index allocation

I am attempting to actually implement that using a GridLayout. Here is what I have so far:

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.commonsware.android.gridlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    app:orientation="horizontal"
    app:columnCount="8">

    <Button
        app:layout_columnSpan="2"
        app:layout_rowSpan="2"
        android:layout_gravity="fill_horizontal"
        android:text="@string/string_1"/>

  <Button
    app:layout_columnSpan="2"
    android:layout_gravity="fill_horizontal"
    android:text="@string/string_2"/>

  <Button
    app:layout_rowSpan="4"
    android:text="@string/string_3"/>

  <Button
    app:layout_columnSpan="3"
    app:layout_rowSpan="2"
    android:layout_gravity="fill_horizontal"
    android:text="@string/string_4"/>

  <Button
    app:layout_columnSpan="3"
    android:layout_gravity="fill_horizontal"
    android:text="@string/string_5"/>

  <Button
    app:layout_columnSpan="2"
    android:layout_gravity="fill_horizontal"
    android:text="@string/string_6"/>

  <android.support.v7.widget.Space
    app:layout_column="0"
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

  <android.support.v7.widget.Space
    android:layout_width="36dp"
    />

</android.support.v7.widget.GridLayout>

I had to introduce the <Space> elements to ensure each column had a minimum width, otherwise, I would have a bunch of zero-width columns.

However, even with them, I get this:

sample GridLayout

Notably:

  • Despite android:layout_gravity="fill_horizontal", my widgets with column spans do not fill the spanned columns

  • Despite the android:layout_rowSpan values, nothing spans rows

Can anyone reproduce the diagram from the blog post using a GridLayout?

Thanks!

  • 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-09T08:39:53+00:00Added an answer on June 9, 2026 at 8:39 am

    It feels pretty hacky, but I managed to get the correct look by adding an extra column and row beyond what is needed. Then I filled the extra column with a Space in each row defining a height and filled the extra row with a Space in each col defining a width. For extra flexibility, I imagine these Space sizes could be set in code to provide something similar to weights. I tried to add a screenshot, but I do not have the reputation necessary.

    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnCount="9"
    android:orientation="horizontal"
    android:rowCount="8" >
    
    <Button
        android:layout_columnSpan="2"
        android:layout_gravity="fill"
        android:layout_rowSpan="2"
        android:text="1" />
    
    <Button
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"
        android:text="2" />
    
    <Button
        android:layout_gravity="fill_vertical"
        android:layout_rowSpan="4"
        android:text="3" />
    
    <Button
        android:layout_columnSpan="3"
        android:layout_gravity="fill"
        android:layout_rowSpan="2"
        android:text="4" />
    
    <Button
        android:layout_columnSpan="3"
        android:layout_gravity="fill_horizontal"
        android:text="5" />
    
    <Button
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"
        android:text="6" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="0"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="1"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="2"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="3"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="4"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="5"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="6"
        android:layout_row="7" />
    
    <Space
        android:layout_width="36dp"
        android:layout_column="7"
        android:layout_row="7" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="0" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="1" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="2" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="3" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="4" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="5" />
    
    <Space
        android:layout_height="36dp"
        android:layout_column="8"
        android:layout_row="6" />
    
    </GridLayout>
    

    screenshot

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

Sidebar

Related Questions

I'm attempting to style the ActionBar, following this blog post: http://android-developers.blogspot.com/2011/04/customizing-action-bar.html With this source
I've been reading this post on the android developer blog about the twitter client
According to this blogpost on android developers blog it should be doable to change
Re this example from the Android developer blog http://android-developers.blogspot.com/2011/04/customizing-action-bar.html It says that to style
I implemented a ViewPager inside my app (according to this recent blog entry: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
I recently came across a forum post in the android developers group. (link below)
I posted this back in May on the [android-developers] Google Group. I never heard
I added TextToSpeech to my app, following the guidelines in the following post: http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
I read carefully the good UI practice from the Google Dev Blog; http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html and
I tried posting this on the Android Developers list and didn't hear anything -

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.