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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:17:45+00:00 2026-06-16T01:17:45+00:00

I have following code for Gridview (To make the Calendar). <GridView android:id=@+id/calendar android:layout_width=fill_parent android:layout_height=fill_parent

  • 0

I have following code for Gridview (To make the Calendar).

    <GridView
    android:id="@+id/calendar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/rl1"
    android:layout_below="@+id/ll2"
    android:columnWidth="250dp"
    android:numColumns="7" >
    </GridView>

Grid_Cell is as follows.

<?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:background="@drawable/calendar_button_selector" >

<Button
    android:id="@+id/calendar_day_gridcell"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/calendar_button_selector"
    android:gravity="center"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#000"
    android:textSize="14.47sp" >
</Button>

<TextView
    android:id="@+id/num_events_per_day"
    style="@style/calendar_event_style"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >
</TextView>

I want to set no space between the rows and columns. like this

Existing view is as following.

Existing image

Please help me out… Thanks in Advance
.

  • 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-16T01:17:47+00:00Added an answer on June 16, 2026 at 1:17 am

    I will try to give you a snippet, but to be honest, there is no point of using a GridView for your case since all you items are there on the screen anyway. You can create a couple of LinearLayouts in a small loop that will get the result.

    I would advice you to set the columnWidth on Runtime according to the screen width.

    And your adapter should be fed with the column width and height to set them when inflating child views. And in this case, you need to get rid of numColumns. Remember that using numColumns along with columnWidth makes no sense especially when you want to fill the whole space. If you want to set the numColumns, remove the columnWidth.

    SOLUTION:

    Here is the outcome:
    enter image description here
    First, we create our layout. In my case, it is the MainActivity‘s layout and is called activity_main.xml. (Notice there is no GridView because I’ll add that later in code):

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/header"
            android:background="#444"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@android:color/white"
            android:text="Dynamic Static GridView" />
    
        <TextView
            android:id="@+id/footer"
            android:gravity="center"
            android:background="#444"
            android:textColor="@android:color/white"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Shush" />
    
    </RelativeLayout>
    

    Our GridView element’s layout is here in the item_grid.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:background="#fff"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

    Now the trick is in MainActivity (I have commented some of the code for you to understand):

    package com.example.dynamicstaticgridview;

    import android.os.Bundle;
    import android.os.Handler;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.GridView;
    import android.widget.RelativeLayout;
    import android.app.Activity;
    import android.graphics.Color;
    
    /**
     * @author Sherif elKhatib
     *
     */
    public class MainActivity extends Activity {
    
        private static String items[]; //these are temporary items :p do not use them
        static {
            items = new String[7*7];
            for(int i=0;i<7*7;i++) {
                items[i] = String.valueOf(i);
            }
        }
    
        int numberOfColumns = 7; //defaulting to 7, you can change it when you know
        int numberOfRows = 7; //defaulting to 7, you can change it when you know
        GridView mGrid;
        ArrayAdapter<String> mAdapter;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
            params.addRule(RelativeLayout.BELOW, R.id.header);
            params.addRule(RelativeLayout.ABOVE, R.id.footer);
            mGrid = new GridView(this) {
                @Override
                protected void onLayout(boolean changed, int l, int t, int r, int b) {
                    super.onLayout(changed, l, t, r, b);
                    if(!calculated)
                        getDimens();
                }
            };
            mGrid.setVerticalSpacing(0);
            mGrid.setHorizontalSpacing(0);
            mGrid.setStretchMode(GridView.NO_STRETCH);
            mGrid.setBackgroundColor(Color.rgb(100, 10, 10));
            ((RelativeLayout)findViewById(R.id.rootview)).addView(mGrid, params);
        }
    
        private int mCellWidth;
        private int mCellHeight;
        boolean calculated = false;
        protected void getDimens() {
            calculated = true;
            //here you might have some rounding errors
            //thats why you see some padding around the GridView
            mCellWidth = mGrid.getWidth()/numberOfColumns;
            mCellHeight = mGrid.getHeight()/numberOfRows;
            mGrid.setColumnWidth(mCellWidth);
            mGrid.setNumColumns(numberOfColumns);
            mAdapter = new ArrayAdapter<String>(this, R.layout.item_grid, R.id.text, items) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    GridView.LayoutParams params = null;
                    if(convertView == null) {
                        params = new GridView.LayoutParams(mCellWidth, mCellHeight);
                    }
                    convertView = super.getView(position, convertView, parent);
                    if(params != null) {
                        convertView.setLayoutParams(params);
                    }
                    return convertView;
                }
            };
            mGrid.setAdapter(mAdapter);
        }
    }
    

    COMMENTS:
    You’d really better find a decent algorithm to choose mCellWidth, mCellHeight, numberOfColumns, and numberOfRows.

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

Sidebar

Related Questions

I have the following layout: <GridView android:id=@+id/gridViewCalendar android:layout_width=match_parent android:layout_height=match_parent android:gravity=center android:numColumns=7 > </GridView> And
I have a gridview in an update panel with the following code to select
I have the following code to export a gridview to excel and the export
I have the following code in the columns section of my GridView: <Columns> <asp:boundfield
I have the following code to insert some data from a GridView to a
I have the following two controls in my code gridview (for data display) sqldatasource
I have the following code in xaml: <ListView Name=listView1 IsSynchronizedWithCurrentItem=True > <ListView.View> <GridView> <GridViewColumn
I have the following code which adds a label and a gridview to an
I have the following code: <ListView Name=lvwYears Margin=0,32,191,29 ItemsSource={Binding Path=YearCollection}> <ListView.View> <GridView> <GridViewColumn> <GridViewColumnHeader>
I have gridview binded from database.. I have following code: protected void Page_Load(object sender,

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.