"Android Development Tips" Ken burns special effects slideshow

Source: Internet
Author: User
Tags event listener

Ken Burns Special Effects is a special effect for panning and zooming a static picture used in video products.

Read Wikipedia's introduction to Ken Burns special effects first.

Http://en.wikipedia.org/wiki/Ken_Burns_effect


To achieve this effect, you need to use the Nineoldandroids library, which can use the Android 3.0 animation library on older versions.


Preparatory work

These animations are performed above the ImageView. The basic idea of the animation execution, when one animation execution is finished, another new animation is executed on the other new ImageView, which is reciprocating.

The main layout uses framelayout, where a imageview is placed. The code is as follows:

    @Override public    void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Mcontainer = new Framelayout (this);        Mcontainer.setlayoutparams (New Layoutparams (layoutparams.fill_parent,                layoutparams.fill_parent));        MView = Createnewview ();        Mcontainer.addview (MView);        Setcontentview (Mcontainer);    }    Private ImageView Createnewview () {        ImageView ret = new ImageView (this);        Ret.setlayoutparams (New Layoutparams (layoutparams.fill_parent,                layoutparams.fill_parent));        Ret.setscaletype (SCALETYPE.FIT_XY);        Ret.setimageresource (Photos[mindex]);        Mindex = (Mindex + 1 < photos.length)? Mindex + 1:0;        return ret;    }
An array of image resources, with the following code:

    private static final int[] PHOTOS = new int[] {r.drawable.photo1,            R.drawable.photo2, R.drawable.photo3, R.DRAWABLE.P Hoto4,            r.drawable.photo5, r.drawable.photo6};
With Createnewview, create a ImageView object to display the next picture.


Writing animations

Write the Nextanimation method, which sets the animation and starts the animation. The code is as follows:

private void Nextanimation () {Animatorset anim = new Animatorset ();        Final int index = Mrandom.nextint (Anim_count); Switch (index) {case 0:anim.playtogether (objectanimator.offloat (MView, "ScaleX", 1            .5f, 1f), Objectanimator.offloat (MView, "ScaleY", 1.5f, 1f));        Break Case 1:anim.playtogether (Objectanimator.offloat (MView, "ScaleX", 1, 1.5f), OBJECTANIMATOR.O            Ffloat (MView, "ScaleY", 1, 1.5f));        Break            Case 2:animatorproxy.wrap (MView). Setscalex (1.5f);            Animatorproxy.wrap (MView). Setscaley (1.5f);            Anim.playtogether (Objectanimator.offloat (MView, "Translationy", 80f, 0f));        Break            Case 3:default:animatorproxy.wrap (MView). Setscalex (1.5f);            Animatorproxy.wrap (MView). Setscaley (1.5f); Anim.playtogether (Objectanimator.offloat (MView, "Translationx",0f, 40f));        Break        } anim.setduration (3000);        Anim.addlistener (this);    Anim.start (); }


Animated Event Listener

The Animatorproxy class is a tool class in the Nineoldandroids library that modifies the properties of a View object. The properties of the view change over time. The Animatorproxy class is used because some properties do not have a setters or getters method in the following versions of Android 3.0.

At the same time, you need to animate the listener, one animation is completed, another new animation is executed on another new ImageView.

@Override public    void Onanimationend (Animator Animator) {        mcontainer.removeview (mView);        MView = Createnewview ();        Mcontainer.addview (MView);        Nextanimation ();    }
In the activity's Onresume callback, call the Nextanimation method. In this way, after entering the activity, Ken Burns slide will begin to execute.


Postscript

The types of animations supported by Android are as follows:

    • Property Animation Properties Animation (Android 3.0 new)
    • Tween Animation Motion Tween animation
    • Frame Animation Frames Animation

Nineoldandroids Library, which is the property animation frame provided by Android 3.0, is translated into Chinese called attribute animation. This animated frame has made a lot of improvements compared to the lower version of the animation frame, so Google is really well-intentioned.

The disadvantages of older versions of animations are as follows:

    • Only the animation effect of the View object is supported. Property animations not only support trying objects, but support everything "objects".
    • Only moves, scales, spins, gradients, etc. are supported.
    • It just changes the visual effect of the View object, not the real property of the View object.

The application of property animation is very extensive, it is worth studying and studying deeply. Although there have been many people on the Internet on the property animation summary and induction, but all things still have to study, in order to be able to understand deeply.


Resources

www.nasatrainedmonkeys.com/portfolio/feedtv/

Https://github.com/JakeWharton/NineOldAndroids

Http://en.wikipedia.org/wiki/Ken_Burns_effect

Http://android-developers.blogspot.com.ar/2011/02/animation-in-honeycomb.html

http://android-developers.blogspot.com.ar/2011/05/introducing-viewpropertyanimator.html/HTTP Android-developers.blogspot.com.ar/2011/05/introducing-viewpropertyanimator.html


SOURCE download

Baidu Network Disk Http://pan.baidu.com/s/1qWwO0bU

"Android Development Tips" Ken burns special effects slideshow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.