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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:25:19+00:00 2026-05-16T14:25:19+00:00

I am trying to display an image from a URL, which may be larger

  • 0

I am trying to display an image from a URL, which may be larger than the screen dimensions. I have it kind of working, but I would like it to scale to fit the screen, and I also have problems when the screen orientation changes. The image is tiny, and I would like it to scale its width to the screen as well. (In both cases, I would like the image to fill the screen width with scrollbars (if necessary for height).

Here is my ImageView:

<ImageView android:id="@+id/ImageView01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true">
</ImageView>

Here is the java code which loads the image: (some error handling code removed for simplicity)

    Object content = null;
    try{
      URL url = new URL("http://farm1.static.flickr.com/150/399390737_7a3d508730_b.jpg");
      content = url.getContent();
    }
      catch(Exception ex)
    {
        ex.printStackTrace();
    }
    InputStream is = (InputStream)content;
    Drawable image = Drawable.createFromStream(is, "src");
    Image01.setImageDrawable(image);

I have tried different settings for android:scaleType. I’m sorry if this question has been asked before. I’ve gone through a number of tutorials on the subject, but they don’t seem to work for me. Not sure if it has anything to do with the way the image is loaded. (from the web instead of a local resource)

Another issue is that sometimes the image doesn’t even load. There are no runtime errors, I just get nothing in the ImageView.

Please let me know if you need more information or clarification.

  • 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-16T14:25:19+00:00Added an answer on May 16, 2026 at 2:25 pm

    the issue about that “sometimes the image doesn’t even load” is related to the context so I used this functions to solve that issue

    public Object fetch(String address) throws MalformedURLException,
        IOException {
            URL url = new URL(address);
            Object content = url.getContent();
            return content;
        }  
    
        private Drawable ImageOperations(Context ctx, String url) {
            try {
                InputStream is = (InputStream) this.fetch(url);
                Drawable d = Drawable.createFromStream(is, "src");
                return d;
            } catch (MalformedURLException e) {
                return null;
            } catch (IOException e) {
                return null;
            }
        }
    

    so to fill the screen width with your image you must have a code like this

        try{
            String url = "http://farm1.static.flickr.com/150/399390737_7a3d508730_b.jpg";           
            Drawable image =ImageOperations(this,url);
            Image01.setImageDrawable(image);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    
    
        Image01.setMinimumWidth(width);
        Image01.setMinimumHeight(height);
    
        Image01.setMaxWidth(width);
        Image01.setMaxHeight(height);
    

    UPDATE::
    if you load a big size image obviously you will have to wait more time, and download problems could be caused for UnknowHostException.

    yes you are right you will save your image locally, the local access is faster than the download.

    to avoid problems on rotation change set your configChanges=”keyboardHidden|orientation” property inside your Manifest.xml

    <activity android:name=".myActivity"
    ...
             android:configChanges="keyboardHidden|orientation"   >
    ...
    />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display image data read in from a binary file (I have
I'm trying to display an image from a URL in a UIImageView and I'm
I'm trying to display the biggest image url returned from an xml result. So
i am trying to display image from internet in my imageview. which is raising
i am trying to display an image from net..and i am using ignition library
I am trying to make general purpose image display class which receives two parameters,
I'm trying to write a method to store an image from a given url,
I'm trying to display an image from a webcam in my app using HJCache
I have a problem with a image when trying to display it. In my
I'm trying to display video from a webcam. I capture the images from the

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.