Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance wise, what is typically better, using an image or a xml created shape as a drawable?

For example, if each row in a list had a background that was a gradient, would it be better to use a image of a gradient or to define that gradient in a shape drawable in xml? Is there is significant performance difference between the two methods?

like image 857
cottonBallPaws Avatar asked Oct 23 '10 23:10

cottonBallPaws


People also ask

Which function is used to load a drawable image resource?

Drawable drawable = ResourcesCompat. getDrawable (res, R. drawable. myimage, null);

Which type of drawable do you use to create a button that shows one background when it is pressed and a different background when it is hovered over?

A StateListDrawable is a Drawable object that uses a different image to represent the same object, depending on what state the object is in. For example, a Button can exist in one of several states (pressed, focused on, hovered over, or none of these).

Which of the following is a drawable object that manages an array of other Drawables with the last drawable on the top of list?

Layer List. A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top. Each drawable is represented by an <item> element inside a single <layer-list> element.


2 Answers

I just asked a similar question and it sounded like that using an image drawable is more efficient computationally than using a vector.(but i'm not expert so don't quote me on that)

It really depends on what your trying to set out to achieve in the first place. If you have completed creative assets that aren't going to change then it would make sense to create bitmaps etc from those.

However, if your prototyping or just beginning to flesh out your application where colours, sizes, transitions etc are likely to change quickly and often then bitmaps really aren't going to help your cause.

During development and up front i'd create a library of drawables i could re-use and update often. Then once everything is complete and signed off and if performance was important i'd revert to images.

If your organised enough you could perhaps use a theme or style to switch between the two.

like image 133
Emile Avatar answered Oct 05 '22 22:10

Emile


Don't prematurely optomize. That's a really hard thing to know what will be better. I would just do it in xml since it would be easier to change.

like image 41
Falmarri Avatar answered Oct 05 '22 22:10

Falmarri