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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:40:32+00:00 2026-05-31T21:40:32+00:00

I’ve got a GridView inside a scrollview and the GridView has 4 images loaded

  • 0

I’ve got a GridView inside a scrollview and the GridView has 4 images loaded into it (via an ImageAdapter). My issue is I can get 3 of the images to show but the 4th doesn’t. After further investigation, I’ve found that the height of the gridview is only the height of the row, so if I set the gridview height in xml to 700dp, then it shows up.

Here’s a screenshot:

enter image description here

As you can see, I’ve set the background of the GridView to HotPink to illustrate where the GridView is.

Here’s the XML for the main_menu:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llLayoutContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >    

    <!-- <LinearLayout android:id="@+id/llMiddle"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"> -->

        <LinearLayout
            android:id="@+id/llLeft"
            android:layout_width="400dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/layout_left"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"> 
            <ScrollView 
                android:id="@+id/svMenu"
                android:layout_width="400dp"
                android:layout_height="match_parent"
                >
            </ScrollView>           
        </LinearLayout>

        <LinearLayout
            android:id="@+id/llRight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:background="@drawable/layout_right"
            android:padding="0dp"> 
        </LinearLayout>
    <!-- </LinearLayout> -->
</LinearLayout>

The LinearLayout “llLeft” is the layout where the menu items get loaded (inside the ScrollView). layout_left is only a shape which draws the dark outline around the greenish background.

Here’s the main_menu_header.xml which contains the GridView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingTop="5dp">

    <TextView
             android:id="@+id/tvDashboardHeader"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:text="Dashboard Main Menu"
             android:textSize="20dp"
             style="@style/TextShadow"
             android:paddingTop="5dp"
             android:gravity="left"
             android:background="@drawable/menu_item_bg"        
            />
    <GridView 
        android:id="@+id/gvMenuItems"
        android:layout_width="400dp"
        android:layout_height="match_parent"
        android:columnWidth="110dp"
        android:numColumns="auto_fit"    
        android:verticalSpacing="10dp"    
        android:horizontalSpacing="10dp"    
        android:stretchMode="columnWidth"
        android:background="@color/HotPink"
        android:gravity="center" >
    </GridView>

</LinearLayout>

And here’s how I populate the GridView:

        ScrollView sv = (ScrollView)findViewById(R.id.svMenu);
        LayoutInflater liInflater = getLayoutInflater();
        ViewGroup vg = (ViewGroup)liInflater.inflate(R.layout.main_menu_header, sv, false);
        sv.addView(vg);

        //Setup the Main Menu items on the left side.
        GridView gvMenuItems = (GridView) findViewById(R.id.gvMenuItems);    
        gvMenuItems.setAdapter(new ImageAdapter(this));

ImageAdapter class:

ImageAdapter class:

public class ImageAdapter extends BaseAdapter {
    private Context mContext;    

    public ImageAdapter(Context c) {
        mContext = c;    
    }    

    public int getCount() {        
        return mThumbIds.length;    
    }    

    public Object getItem(int position) {        
        return null;    
    }    

    public long getItemId(int position) {        
        return 0;    
    }    

    // create a new ImageView for each item referenced by the Adapter    
    public View getView(int position, View convertView, ViewGroup parent) {        

        ImageView imageView;

        if (convertView == null) {
            // if it's not recycled, initialize some attributes            
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(parent.getLayoutParams().width, 125)); //new GridView.LayoutParams(400, 125));             
            //imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setMaxHeight(50);
            imageView.setMaxWidth(50);
            //imageView.setPadding(30, 0, 0, 0);
            //imageView.setPadding(40, 30, 20, 30);

            } else {            
                imageView = (ImageView) convertView;        
            }        

        imageView.setImageResource(mThumbIds[position]);

        return imageView;
    }    

    // references to our images    
    private Integer[] mThumbIds = {
            R.drawable.home,
            R.drawable.open_folder, 
            R.drawable.paper_pen,
            R.drawable.person
    };
}

I thought the gridview property of android:layout_height=”match_parent” would work but it’s not. Any ideas as to how I can get the GridView to take up the whole left side, inside the scrollview?

  • 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-31T21:40:34+00:00Added an answer on May 31, 2026 at 9:40 pm

    My best guess is that scrollview is giving you problem.

    Why do u need scrollview for?

    Grid View will handle the scrolling. It is kind of redundant.So please remove it and add inflated view directly to llLeft directly. That shall solve the problem.


    In fact, it would be more elegant just to use xml to solve your UI problem. Use <include> tag in your main_menu.xml. Here is how

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llLayoutContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >    
    
    <!-- <LinearLayout android:id="@+id/llMiddle"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"> -->
    
        <LinearLayout
            android:id="@+id/llLeft"
            android:layout_width="400dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/layout_left"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"> 
            <include
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             layout="@layout/main_menu_header" />           
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/llRight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:background="@drawable/layout_right"
            android:padding="0dp"> 
        </LinearLayout>
    <!-- </LinearLayout> -->
    

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.