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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:23:52+00:00 2026-06-16T19:23:52+00:00

I am using a GridView that shows a linearlayout with a background image plus

  • 0

I am using a GridView that shows a linearlayout with a background image plus a text, just like this example:

http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/

And just like that very example, I am using that code to make the images have round corners.

The problem is, if I don’t use the round corner thingy, all my grid items are the same height, no matter what text they have inside, even though all my images are of the same size.

But if I use it, the items height is wrapped to the content.

I tried defining my linear layout to wrap_content, fill_parent, match_parent and even fixed heights, but the system just ignores me.

This is my grid layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFDDDDDD"
    android:orientation="vertical"
    tools:context=".RouteListActivity" >

    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="20dp"
        android:layout_weight="2"
        android:animateLayoutChanges="false"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:drawSelectorOnTop="true"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:numColumns="2"
        android:scrollingCache="false"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10dp" />

</LinearLayout>

And this is my grid item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayoutGridLabel"
    android:layout_width="wrap_content"
    android:layout_height="150dp"
    android:layout_weight="1"
    android:gravity="bottom|left"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/id_ruta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:visibility="gone" />

    <TextView
        android:id="@+id/routenameGridLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:background="#77000000"
        android:gravity="bottom"
        android:padding="5dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

Plus my getView in the Adapter:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.grid_item, null);

        LinearLayout linLayout = (LinearLayout) vi.findViewById(R.id.linearlayoutGridLabel);
        Typeface yanone = Typeface.createFromAsset(mContext.getAssets(), "YanoneKaffeesatz-Regular.ttf");
        TextView id_ruta = (TextView) vi.findViewById(R.id.id_ruta);
        TextView nombre=(TextView)vi.findViewById(R.id.routenameGridLabel);
        nombre.setTypeface(yanone);
        nombre.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 38);
        Ruta current = routeList.get(position);
        try {
//          Drawable d;
//          d = Drawable.createFromStream(mContext.getAssets().open("ruta" + (position+1) + "/title.jpg"), null);
            Bitmap b = BitmapFactory.decodeStream(mContext.getAssets().open("ruta" + (position+1) + "/title.jpg"));
            StreamDrawable d = new StreamDrawable(b, 10, 0);
            linLayout.setBackgroundDrawable(d);
        } catch (IOException e) {
            linLayout.setBackgroundResource(R.drawable.noimage);
        }
        nombre.setText("" + current.getNombre());
        id_ruta.setText(current.getId().toString());

        return vi;
    }

Frankly, I don’t understand gridviews behavior. Previously I had different sizes images set as background images, and all elements overlapped each other. I couldn not get to make rows of the same size even when fixing height on the grid item’ layout.

Can I get some directions here, please?

  • 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-16T19:23:53+00:00Added an answer on June 16, 2026 at 7:23 pm

    I finally solved it, turns out the problem was in that I was using

    vi = inflater.inflate(R.layout.grid_item, null);
    

    instead of

    vi = inflater.inflate(R.layout.grid_item, parent, false);
    

    so layout parameters were being ignored.

    Anyway, getting GridView to evenly distribute space is a pain in the ass. I think I will be switching to TableView.

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

Sidebar

Related Questions

i am trying to display image using GridView. This is the first time i
I'm using a GridView to show a set of Categories that user can chose.
We're using a WPF GridView that is dynamically bound to a DataTable (which in
Hi i m using GridView with hovermenu and i want that when we click
I've got a WPF ListView that I'm using as a GridView. Is there any
I'm running an app that pulls images using a URL into a gridView, the
Here's the code for the GridView Control that I'm using (made on BlankPage App):
I have a Gridview that shows a list of Contacts via a sqlDataSource. Included
I am trying to hide paging numbers on gridview that shows on bottom of
I have a gridview that shows records from a database table. Now, I want

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.