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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:34:55+00:00 2026-05-15T12:34:55+00:00

I will try to be as clear as possible. Here What I am trying

  • 0

I will try to be as clear as possible.

Here What I am trying to do

An Image Viewer, where Image would be display as big as they can on the device screen.
For this purspose and for a better user experience, I thought of a Gallery.
Untill there everything is OK!

The problem

The problem is that in the function getView of my Adapter, it uses only the Gallery.LayoutParams of the first Image I have in my Gallery. Which means that if the first picture is a landscape and the second one a portrait the second one will be display as landscape, with the same dimension as the first one. I do reset the Gallery.LayoutParams but it does not matter, it still have the LayoutParams of the first ImageView.

The code

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

        ImageView im = new ImageView(mContext);

        Bitmap bm = BitmapFactory.decodeByteArray(gallery.get(position).mContent, 0, gallery.get(position).mContent.length);
        im.setImageBitmap(bm);

        int width = 0;
        int height = 0;

        if (bm.getHeight() < bm.getWidth()) {
            width = getWindowManager().getDefaultDisplay().getWidth();
            height = bm.getHeight() * width / bm.getWidth();
        }
        else {
            height = getWindowManager().getDefaultDisplay().getHeight();
            width = bm.getWidth() * height/ bm.getHeight();
                }

        Gallery.LayoutParams lp = new Gallery.LayoutParams(width, height);
        im.setLayoutParams(lp);

        return im;
}

If any of you see why I would be really please to know the answer,

  • 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-15T12:34:55+00:00Added an answer on May 15, 2026 at 12:34 pm

    Gallery forces all children to have the same size. Also, you are creating a new View every time getView() is called and it’s a terrible idea. You should use the convertView when it’s not null. There’s currently a missing feature in Gallery so convertView is always null, but to benefit from it in a future version of Android, use the convertView anyway. It’s also a good practice that you must apply in every Adapter you write.

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

Sidebar

Related Questions

I will try to be as clear as possible because I can't get anybody
Been a tough week, will try to make this as clear as possible. Appreciate
Let me try and be as much clear as possible although it won't be
Sorry if the post title wasn't clear, I will try to explain a little
I think this may not be possible, will try and explain as best as
Ok I will try to explain this as much as possible. I have a
I am working on an algorithm that will try to pick out, given an
I'm fairly new to C# but I will try to make this quick! ;)
This might be a little hard to explain, but I will try. I want
I'm try to develop a regex that will be used in a C# program..

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.