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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:55:32+00:00 2026-06-09T21:55:32+00:00

I want to create a DialogFragment in android with 2 components: A GridView on

  • 0

I want to create a DialogFragment in android with 2 components:
A GridView on the left with images and a big image on the right (which is the bigger version from the selected image in the gridview).

The problem is that I can’t see my big image. It seems like GridView is taking all the space.

This is my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal" 
android:background="#FFFFFF">

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/image_overview"
android:layout_width="wrap_content" 
android:layout_height="fill_parent"
android:columnWidth="50dp"
android:numColumns="1"
android:gravity="left"
android:background="#FFFFFF"
/>

<ImageView
android:id="@+id/main_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#FFFFFF"
/>
</LinearLayout>

I already tried a lot of the parameters to see if it makes any difference, but nothing helps. My gridview is small (because I put a small size), but the space on the right is empty.

If I remove my gridview, I can see the big image.
If I put a specific width for my gridview, I can also see my big image.

So if I change following line for the GridView

    android:layout_width="wrap_content" 

by

    android:layout_width="100dp" 

it works as expected.
It looks like wrap_content is setting a much bigger width.

This is the code for creating my topvew (some code is comment because I tried some stuff to see if it has any impact):

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    getDialog().setTitle("Title Item");

    //Get complete View
    topView = inflater.inflate(R.layout.something, container, false);
imageAdapter = new ImageAdapter(this.getDialog().getContext());

    //Create the left panel (gridview of small images)
    GridView gridview = (GridView)topView.findViewById(R.id.image_overview);
    gridview.setAdapter(imageAdapter);
    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            currentBigImage = imageAdapter.getFilePath(position);
            updateMainImage();
        }

    });

    //gridview.setAdjustViewBounds(true);

    //Create the middle panel (big image)
    imageView = (ImageView)topView.findViewById(R.id.main_image);
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    //imageView.setAdjustViewBounds(true);
    //imageView.setPadding(8, 8, 8, 8);
    updateMainImage();
    //v.invalidate();

    return topView;
}

This is the code from my adapter (creating a single view for the small image):

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(50, 50));
        //imageView.setAdjustViewBounds(true);
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }
    imageView.setImageBitmap(BitmapFactory.decodeFile(paths.get(position)));
Log.i("parent.getWidth(): ", ""+parent.getWidth());
    return imageView;
}

As you can see, I’m also printing the width of the parent, which is a very big number. Because the view here is a single item in the gridview, I assume the parent is the gridview? If so, I’m not sure if it’s normal that the width is big, because it’s configured on wrap_content, but maybe that’s normal even with wrap_content if Android creates a dialog with a specific size.

Anybody has an idea how I could use wrap_content instead of fixed size?

  • 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-09T21:55:34+00:00Added an answer on June 9, 2026 at 9:55 pm

    First of all, thanks Andy Harris & Dipak Keshariya for your help. It didn’t fully solved the problem, but it helped me understanding that android:layout_weight=”0″ can lead to problems.

    Before I posted my answer here, I already tried to configure

    android:layout_weight="1"
    

    for the imageview only, but that didn’t work.
    Putting it on 1 for both, does make the ImageView visible, however, it’s not correctly displayed. The size of the imageview seems correct, but is shows a part of the image in big (so zoomed in).

    I tried to play with ImageView.ScaleType and AdjustViewBounds, but nothing works.

    If I configure

    android:layout_weight="1"
    

    only for the GridView, it shows the GridView and the ImageView both correctly, but in that case, the gridview takes up all the corresponding width, which makes the dialog as width as the screen of the tablet (changing width of the parentview to match_parent doesn’t change that).

    So I will keep on using the fixed size for now.

    Thanks for the help!

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

Sidebar

Related Questions

i want create image animation , i have 50 images with png format now
I want create texture atlas(matrix of images) from multiple images.Is their any applescript that
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want create module which update list of usb devices automatically (not only mass
I want to create a Silverlight app to extract and manipulate data from an
I want create some view, and add dynamically to it text and images Somebody
I want create a pdf using iText. The method which does this is a
I want create a generic (general) method which accepts the return types of LINQ

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.