M
M
mitaichik2016-06-05 22:27:02
Android
mitaichik, 2016-06-05 22:27:02

Is it possible to use one Drawable instance as a background to multiple Views?

Hello everyone, there is a RelativeLayout with about 100 View elements. Each of these views is set (programmatically) to Drawable as a background. There are 4 background options in total, and I was thinking of creating 4 Drawable instances (one per option) and passing them to all Views.
Will this work correctly on all android versions (2.3 - 6)?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Gapchenko, 2016-06-06
@artemgapchenko

As far as I remember, when you set a drawable via setBackgroundResource(), Android internally caches the loaded drawable, and reuses the created entity on subsequent calls. So you don't need to do anything extra.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question