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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:28:35+00:00 2026-06-05T10:28:35+00:00

It is advantageous in my application if I preload certain images. I do this

  • 0

It is advantageous in my application if I preload certain images. I do this correctly, in AsyncTask, as it is written in the official documentation. But I have a problem/question about when they should be set.

I’ll show code snippets. Note that it’s simplified (their interoperability is better in my real code, it checks for nulls, etc.).

Let’s see the original (non-preloaded) version first:

<ImageView
    android:id="@+id/imageViewMyGraphicalImageElement"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="centerCrop" 
    android:src="@drawable/my_graphical_element" >
</ImageView>

The preloaded version has the following XML (notice that the src attribute is missing):

<ImageView
    android:id="@+id/imageViewMyGraphicalImageElement"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="centerCrop">
</ImageView>

And a snippet from the preload code:

sBitmap = bitmapBitmapFactory.decodeResource(context.getResources(), R.drawable.my_graphical_element, options); 
// 'sBitmap' is a Bitmap reference, while 'options' is BitmapFactory.Options

Finally, the place where I set it:

setContentView(R.layout.main);
...
ImageView imageViewMyGraphicalImageElement= (ImageView) findViewById(R.id.imageViewMyGraphicalImageElement);
imageViewMyGraphicalImageElement.setImageBitmap(sBitmap); 

Question:
Obviously, the xml-based solution knows about the image before setContentView(…) is called. The preload version sets the image after that call. Is there any difference? Can some autoscaling or other things done by the system be skipped due to this?

  • 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-05T10:28:37+00:00Added an answer on June 5, 2026 at 10:28 am

    There is no difference at all. You can consider that all the ImageView constructor does with the android:src attribute is call setImageResource.

    Update: Actually it uses setImageDrawable, this is the actual code for ImageView constructor taking attributes:

        Drawable d = a.getDrawable(com.android.internal.R.styleable.ImageView_src);
        if (d != null) {
            setImageDrawable(d);
        }
    

    Reference: ImageView.java

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

Sidebar

Related Questions

Hopefully this question is not to confusing, but I can help clear it up
I have written an application which uses a pipeline of 15 XSL stylesheets, and
We have a PHP application, and were thinking it might be advantageous to have
In my first attempt at an MVC web application I have a fundamental question:
I would prefer if those who answer this question state whether or not they
I have an application that can not afford to lose data, so Postgresql is
I am developing an application which doesn't have large requirements for data storage. I
I am creating the model for a web application. The tables have ID fields
Possible Duplicate: What are the advantages of delegates? I have created a sample application.
I have an application built with Django. Part of it relies on data that

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.