I just checked this link in the doc since I wanted to have some background animations and had some custom animations in png images. And the only way to animate bitmaps was to use the Animate Drawable Graphics. Suppose If I have a looping animation of 3 seconds and I wanted to display at 25fps then this would be a nightmare for storing the png files for multiple devices like: xhdpi
, xxhdpi
, xxhdpi
and so on. Is there any alternative way to go about doing this?
Asked
Active
Viewed 31 times
1

juztcode
- 1,196
- 2
- 21
- 46
-
You need not to store pngs for all xxxhdpi, xxhdpi, xhdpi, hdpi, mdpi, ldpi. Just store for the largest i.e. xxxhdpi. It will take care for all others. Try out. – Jaimin Modi Dec 13 '19 at 04:46
-
it will scale down? I thought that wasn't done by android – juztcode Dec 13 '19 at 05:17
-
Yes it will. Have you tried? – Jaimin Modi Dec 13 '19 at 05:24
-
I had used larger files previously and it resulted in OutOfMemory errors so I didn't try it out this time. But I put the larger files in the drawable folder and not the drawable hdpi folder... I will try it once – juztcode Dec 13 '19 at 05:58
-
1Have you added it in drawable forlder or drawable-xxxhdpi ? Add it in drawable-xxxhdpi instead of only drawable. It will work for sure. There will be no OutOfMemory Error. – Jaimin Modi Dec 13 '19 at 06:00
-
yes it seems to be true, thanks for the advice. :-) – juztcode Dec 13 '19 at 08:43
-
1thanks. keep going.;) – Jaimin Modi Dec 13 '19 at 10:16
-
BTW , do you have any hints to handle animation for a device that is square in dimension and a device that is rectangular? – juztcode Dec 13 '19 at 10:44
-
are you getting xp point value for animation? You can calculate height and width of different devices dynamically in your java or kotlin file using DisplayMetrics class and it's method getMetrics(). So, animation will reflect accordingly for different devices. Here, is the link : https://stackoverflow.com/questions/4743116/get-screen-width-and-height-in-android – Jaimin Modi Dec 13 '19 at 10:51
-
what I meant was the if the same images were used in those devices then the frames would suffer squishing and stretching, because for animation purposes, the images should fit the screen – juztcode Dec 13 '19 at 13:13
-
Not getting stil properly. But, I think you are talking about fitting the image properly. You can use properties of ImageView inside your xml. Use scaleType to fitXY to fit the image fully. You can also check for other values. – Jaimin Modi Dec 14 '19 at 12:57
-
hm.... If we use say a 4096X4096 image which is a square, it might look fine in a similar dimensioned device but for a 500X700 device, the image would appear squished, right? But if I use something like centercrop it then the image would not fully expand the view, so the problem is not handled, ... until we maintain images/animations for small and large devices separately? – juztcode Dec 15 '19 at 17:01
-
1You : centercrop it then the image would not fully expand the view. Me : mostly developer uses fitXY but still let me check something which can solve your issue. will be back to you if i got something. – Jaimin Modi Dec 16 '19 at 04:57