سؤال

I have a framelayout in the layout for a row in a ListView. When an item appears in the listview an AnimationDrawable is triggered.

This works fine on the Nexus 4 and Nexus 5. I had to change from using view.setBackground to view.setBackgroundDrawable to support slightly older devices. Making this change hasn't broken it on either of the Nexus devices. It also worked on an old gingerbread device.

On the HTC One V, running 4.03. the AnimationDrawable never appears. If, however, I hardcode the row xml file to show a standard drawable, rather than the animationdrawable, it appears fine.

Here is the xml file the animationdrawable

<item
    android:drawable="@drawable/alert_red"
    android:duration="700"/>
<item
    android:drawable="@drawable/alert_red_glow"
    android:duration="700"/>

</animation-list>

Here is the code which starts the animation

@SuppressWarnings("deprecation")
        public void startGlowingRow() {
            notificationStatus
                    .setBackgroundDrawable(getResources().getDrawable(
                                R.drawable.glowing_emergency_notification));
            glowRequest = new GlowRequest();
            notificationStatus.post(glowRequest);

        }

        public void stopGlowingRow() {
            try {
                // Remove any callbacks to make background glowing
                if (glowRequest != null)
                    notificationStatus.removeCallbacks(glowRequest);

                glowDrawable = (AnimationDrawable) notificationStatus
                        .getBackground();
                glowDrawable.stop();
            } catch (ClassCastException cce) {
                // Not the correct background in view so don't try to stop
            }
        }

        // Runnable which sets glowing effect after view has loaded
        private class GlowRequest implements Runnable {

            public void run() {

                glowDrawable = (AnimationDrawable) notificationStatus
                        .getBackground();
                glowDrawable.start();
            }

        }
هل كانت مفيدة؟

المحلول

I finally figured this out. It was because the view that contained the animation was using padding to show it's background. When I changed this so that it's first child used a margin instead it worked just fine

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top