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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:36:37+00:00 2026-05-27T19:36:37+00:00

I have an ImageView which will display an image from the web. I used

  • 0

I have an ImageView which will display an image from the web. I used a AsyncTask to load the image and render the image in the onPostExecute event of the AsnycTask. The image loaded from the web may be very large in size, and cannot be decoded in a phone, so I have to know the size of the image view and re-size the image at run-time.

The View class has getWidth and getHeight methods, but I do not know when it is safe to invoke them. I tried to call these methods in the containing Fragments’ onCreateView event, but both return 0; if I call these methods in the onPostExecute event of the AsyncTask, the return value is non-zero and correct.

So I am thinking when is the best point to call these methods and get the view’s 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-05-27T19:36:38+00:00Added an answer on May 27, 2026 at 7:36 pm

    This is one of the things android does really badly. There is no hook you can access to tell when a view, activity, or fragment has actually been measured. The best thing to do is set a default size for the image view in dp (preferably in xml, but you can also do it programmatically using LayoutParams). Then as Paresh suggested, you can just use scaleType to resize the images.

    If you really want to get the width and height of a view, you will need to subclass the view and override onSizeChanged and do whatever it is you want to do based on the width and height there.

    Keep in mind that if you are downloading multiple really large images from the web and then resizing them just using image views scaleType you will probably run into memory warnings and exceptions in some phones. You might want to take a look at the following thread: Strange out of memory issue while loading an image to a Bitmap object

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

Sidebar

Related Questions

I have a listview which includes 2 textviews and 1 imageview. Now, the image
I currently have a application which will display the time allocated to a user
I have a custom listview which display an image, textview and radio button. I
I have an image pattern which I want to display in a UIImageView. The
I have an Imageview which is zoomed and rotated(I have used multitouch zooming ).
I have an imageview which will have a fixed size: layout_width=100dip layout_height=50dip but the
I have an application in which I am displaying image in my imageview which
I have a ImageView which shows a picture that has been taken from the
I have used ImageView's before and understand the different scale types that can be
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?

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.