Animated commentary on Android frame animation, moving position, zooming, changing transparency, etc.
Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 14px"><strong>1. The demand of bitter force came again, need to realize some animation effect, the first thought is to play GIF pictures, but this will occupy the resources of the package, and the clarity is not high, so think of the program implementation, their own frame animation + zoom + mobile + Transparency to achieve a number of effects, here to share with you</strong></span></p></p><p><p><br></p></p><p><p><span style="font-size: 14px"><strong>2. for example, the following:</strong></span></p></p><p><p></p></p><p><p><br></p></p><p><p><strong><span style="font-size: 14px">3. Frame Animation Implementation code</span></strong></p></p><p><p><span style="font-size: 12px">1). First get the ImageView control displayed per frame, then put all the frames into the animationdrawable object, turn on the animation, turn off the animation by handle delay for 2 seconds</span></p></p><p><p></p></p><pre name="code" class="java"><pre name="code" class="java">ImageView ivframe = (ImageView) Findviewbyid (r.id.iv_frame);//get animationdrawable Demo sample final by Frame-wise animation of the resource file Animationdrawable Frameanim = (animationdrawable) getresources (). getdrawable (r.drawable.thank_you_boss_anim); Ivframe.setbackgrounddrawable (frameanim);//set animationdrawable to ImageView background frameanim.start (); new Handler (). postdelayed (new Runnable () {@Overridepublic void run () {if (frameanim! = null && frameanim.isrunning ()) {// 2 seconds to end animation Frameanim.stop ();}}},2000);</pre></pre><br><p><p></p></p><p><p><span style="font-size: 12px">2). Thank_you_boss_anim.xml All frames of the layout file set each frame of the picture, time per frame</span></p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html"><?xml version= "1.0" encoding= "utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android " android:oneshot=" false "> <!--define an animation frame, drawable to img0, duration 300 Ms--and <item android:drawable= "@drawable/icon_think_boss_one" android:duration= "/> <item android:drawable=" "@drawable/icon_think_boss_two" android:duration= "/> <item android:drawable=" @drawable/icon_ Think_boss_three " android:duration=" "/> <item android:drawable=" @drawable/icon_think_ Boss_four " android:duration="/></animation-list></pre></pre><br><p><p></p></p><p><p><br></p></p><p><p><br></p></p><p><p><strong><span style="font-size: 14px">4. Frame Animation Plus mobile zoom transparency effect</span></strong></p></p><p><p><span style="font-size: 12px">turn on a dialog and set the background Transparent. Get the frame animation with the text picture display imageview, and then turn on two animations. </span></p></p><p><p></p></p><pre name="code" class="java">/** * Thank you local tyrants for playing */private void Thanktuhaoreward () {View view=layoutinflater.from (this). Inflate (r.layout.activity_thank_ tuhao_reward,null); final Dialog tyrantdialog = new Dialog (this,r.style.selectordialog); Tyrantdialog.findviewbyid ( r.id.iv_frame); Tyrantdialog.setcontentview (view); Tyrantdialog.setcanceledontouchoutside (true); ImageView ivframe= (ImageView) Tyrantdialog.findviewbyid (r.id.iv_ Frame),//the animationdrawable Demo Sample final animationdrawable frameanim= (animationdrawable) getresources () is obtained by framing the resource file by frame Animation. Getdrawable (r.drawable.thank_you_tyrant_anim); ivframe.setbackgrounddrawable (frameanim);// Set animationdrawable to ImageView background frameanim.start (); ImageView playthinkonetext= (ImageView) Tyrantdialog.findviewbyid (r.id.play_think_one_text); Animation Anim = animationutils.loadanimation (this,r.anim.translate_thank_you_tyrant); Playthinkonetext.startanimation (anim); anim.setfillafter (true); tyrantdialog.show (); view.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View arg0) {stop (frameanim); Tyrantdialog.cancel ();}); Anim.setanimationlistener (new animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {}@ overridepublic void onanimationrepeat (Animation Animation) {} @Overridepublic void Onanimationend (Animation Animation) {stop (frameanim); Tyrantdialog.cancel ();}});} /** * Stop playing */protected void stop (animationdrawable frameanim) {if (frameanim! = null && frameanim.isrunning ()) {FR Ameanim.stop ();}}</pre><br><p><p></p></p><p><p></p></p><p><p><span style="font-size: 12px">Frame animation layout file I'm not going to post it. move, zoom, change the transparency of the layout file Translate_thank_you_tyrant.xml</span></p></p><p><p></p></p><pre name="code" class="html"><?xml version= "1.0" encoding= "utf-8"?<p><p></p></p><p>><set xmlns:android= "http://schemas.android.com/apk/res/android" > <translate android:duration= "1000 "android:fromxdelta=" "android:fromydelta=" "android:toxdelta=" "android:toydelta="-120 "/> <alpha android:duration=" android:fromalpha= "0.4" android:toalpha= "1.0"/> & Lt;scale android:duration= "" "android:fillafter=" false "android:fromxscale=" 0.4 "android:fr omyscale= "0.4" android:interpolator= "@android: anim/accelerate_decelerate_interpolator" android:pivotx= "50%" android:pivoty= "50%" android:toxscale= "1.0" android:toyscale= "1.0"/> <!--translate position turn Move drawing effect Integer value: The Fromxdelta property is the position of the x-coordinate at the start of the animation Toxdelta property is the position on the x-coordinate at the end of the animation Fromydelta property is dynamic Position of the y-coordinate at the start of the drawing Toydelta property is the position of the y-coordinate at the end of the animation note: Fromxtype Toxtype fromytype Toytype is not specified. The default is to use your own relative to the long integer value: The Duration property is an animation duration description: the time is in milliseconds--></set> </p></pre><br><p><p></p></p><p><p><span style="font-size: 32px">Click to download source code</span><br></p></p><p><p><br></p></p><p><p></p></p> <p><p>Animated commentary on Android frame animation, moving position, zooming, changing transparency, etc.</p></p></span>
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