Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do multiple ImageView's holding the same image create extra Drawable objects or Drawable instances?

Tags:

android

I currently have a ViewFlipper that holds the same ImageView in each screen. The issue is that I have to create an ImageView[] array with a unique ImageView per screen in the ViewFlipper in order to add them to the ViewFlipper since I run into the child already has a parent issue when using the same ImageView. They all refer to the same resource in R.drawable.

My question is this: does every ImageView in the array create a separate instance of the drawable object or do they each simply contain a reference to the same drawable object? Also, are ImageView instances resource intensive? I'm worried that this would run into overhead issues, since this ImageView array isn't the only one.

like image 896
Zaid Daghestani Avatar asked Oct 31 '25 14:10

Zaid Daghestani


1 Answers

As far as drawables loaded from the same resource share a common state it seems that android architects have thought of this question and the resources are used for 1 image only, so you won't get overhead in such way.
In addition: BitmapDrawables created from the same resource will for instance share a unique bitmap stored in their ConstantState.

like image 73
ernazm Avatar answered Nov 02 '25 05:11

ernazm