Hello all, I'm trying to perform an AnimationDrawable with a custom "waiting picture", in the way described here : - http://developer.android.com/guide/topics/graphics/2d-graphics.html#frame-animation - http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
My goal is to have a waiting animation for each picture of a Gallery View, while picture is loading (through web or whatever). I have a custom view which include an ImageView for the loading animation + a Gallery that we be filled with this custom view. My first issue is to properly call the start() method on the animation. Indeed this should not be called right after calling the ImageView constructor. On the DevGuide link (see above), it's recommended to perform the start() call in the onWindowFocusChanged() method of your activity. This doesn't work properly in my case, as the elements of Gallery that are not visible are not yet built (they will be built only in the getView of the Gallery adapter). So, I have no choice but to use one trick or another, for instance calling start() after a given delay, hoping the ImageView would be OK at this time. My second issue is to keep the animation going on. I use the "animation-list" with "android:oneshot="false"", which is OK when the animation is on screen. But when the user scroll the gallery so as the animation becomes no longer visible, the animation automatically stops. When the user scrolls back to the animation, it is no longer running. So my questions are : - Is there any built-in way of performing a waiting animation before the gallery's picture load ? - When should be called the start() method ? - How can I ensure the animation is always running, even after getting out of screen bounds ? Regards, G. PS, some pieces of code I use : anim/wait.xml <animation-list xmlns:android="http://schemas.android.com/apk/res/ android" android:oneshot="false"> <item android:drawable="@drawable/loader_large_01" android:duration="100" /> <item android:drawable="@drawable/loader_large_02" android:duration="100" /> </animation-list> layout/main.xml <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@anim/wait"></ ImageView> <Gallery android:id="@+id/Gallery01" android:layout_width="fill_parent" android:layout_height="wrap_content"></Gallery> public class Test extends Activity { public void onCreate(Bundle savedInstanceState) { Gallery g = (Gallery) this.findViewById(R.id.Gallery01); g.setAdapter(adapter); } private AnimationAdapter adapter = new AnimationAdapter(); private class AnimationAdapter extends BaseAdapter { private AnimationDrawable[] cache = new AnimationDrawable[15]; public View getView(int position, View convertView, ViewGroup parent) { View v = new ImageView(Test.this); v.setBackgroundResource(R.anim.wait); v.setLayoutParams(new Gallery.LayoutParams(100, 100)); this.cache[position] = (AnimationDrawable) v.getBackground(); this.cache[position].setVisible(true, true); return v; } (...) public void start() { for (int i = 0; i <= this.cache.length - 1; i++) { if (this.cache[i] != null) { this.cache[i].start(); } } } }; public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); this.adapter.start(); } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

