0

I have to add up to 100 .png's to create an AnimationDrawable on Android.

Luckily, the png's are named in ascending order (p1, p2, p3, p4).

Manually adding all pngs into the XML element is painfully slow, so I'm wondering if there's a way to automatically 'increment' a filename to a certain limit.

The method does not have to use Android Studio. Any text manipulation program will do. Below is an example of a desired result:

<animation-list android:id="@+id/selected"
android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/p1" android:duration="500" />
<item android:drawable="@drawable/p2" android:duration="500" />
<item android:drawable="@drawable/p3" android:duration="500" />
<item android:drawable="@drawable/p4" android:duration="500" />
...
...
...
<item android:drawable="@drawable/p99" android:duration="500" />


</animation-list>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • A decent text editor should have a "macro" feature. Possibly using variables or whatsoever. – Phantômaxx Jul 25 '17 at 18:28
  • 1
    I'd say do it in code. Bonus: if you do it right you can change the number of drawables in it without xml or code changes that way. – Gabe Sechan Jul 25 '17 at 18:29

1 Answers1

0
  • Create the sequence from 1 to 99 in MS Excel/Apple Numbers/Google Sheets
  • Copy the entire sequence to your favorite text editor
  • Search with a regex for new lines (\n)
  • Using Sublime or Atom, press Alt + Enter
  • Move to the start of the line paste item android:drawable="@drawable/p
  • Now, move to the end of the line and paste " android:duration="500" />
Jorge E. Hernández
  • 2,800
  • 1
  • 26
  • 50