Android Easy Tutorial-the 63rd shot (animation to achieve the album Playback interface)

Source: Internet
Author: User

For the use of Android animation, record playing is a very classic example, we achieve the record playing effect to the Android animation learning, has a high interest and practicality.

1. First we define the layout file-pan_layout.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:id=" @+id/layout_pan "android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:layout_centerhorizontal= "true" android:layout_centervertical= "true" android:layout_margintop= "30DP" Android        oid:gravity= "center" android:orientation= "vertical" > <framelayout android:layout_width= "wrap_content"            android:layout_height= "Wrap_content" > <imageview android:layout_width= "wrap_content"            android:layout_height= "Wrap_content" android:src= "@drawable/game_title"/> <textview Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_gravity=     "Center" android:text= "song" android:textcolor= "@color/white" android:textsize= "20sp"/> </FrameLayout> <fraMelayout android:layout_width= "260DP" android:layout_height= "wrap_content" > <imageview Android:id= "@+id/imageview1" android:layout_width= "wrap_content" android:layout_height= "Wrap_con            Tent "android:layout_gravity=" center "android:src=" @drawable/game_disc "/> <imageview Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_gr avity= "center" android:src= "@drawable/game_disc_light"/> <imagebutton android:id= "@+id            /btn_play_start "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "            android:layout_gravity= "center" android:background= "@drawable/play_button_icon"/> <imageview            Android:id= "@+id/imageview2" android:layout_width= "50sp" android:layout_height= "140SP" Android:layout_graVity= "Right" android:src= "@drawable/index_pin"/><!--lever--</framelayout></linearlayout& Gt

Here we have widely used the framelayout layout, which can be nested.

2. Define the animation file, here we use a total of three animated ask Price

A.rotate.xml (rotation animation of the intermediate disc)

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" ><!--once 2400 milliseconds, repeat 3 times--    <rotate        android:duration= "2400"        android:fromdegrees= "0"        android:pivotx= "50%"        android:pivoty= "50%"        android:repeatcount= "3"        android:todegrees= "359"/>< /set>

B.rotate_45.xml (dial lever into disc animation):

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <rotate        android:duration= "android:fromdegrees="        0 "        android:pivotx=" 45%        " Android:pivoty= "10%"        android:repeatcount= "0"        android:todegrees= "/></set>"

C.rotate_d_45.xml (dial lever left disc animation):

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <rotate        android:duration= "android:fromdegrees="        android:pivotx= "45%        " Android:pivoty= "10%"        android:repeatcount= "0"        android:todegrees= "0"/></set>
3.mainactivity.java:

Package Com.yayun.guessmusic.ui;import Android.app.activity;import Android.os.bundle;import android.util.Log; Import Android.view.view;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.animationutils;import Android.view.animation.linearinterpolator;import Android.widget.imagebutton;import Android.widget.ImageView; Import Com.yayun.guessmusic.r;public class Mainactivity extends Activity {//album-related animation private Animation mpananim;private Linearinterpolator mpanlin;//Animation constant play private Animation mbarinanim;private Linearinterpolator mbarinlin;// Animated constant play Private Animation mbaroutanim;private linearinterpolator mbaroutlin;//Animation constant play//record control private ImageView mviewpan;/ /lever Control private ImageView mviewpanbar;//Play key event Private ImageButton mbtnplaystart;//whether the current animation is running private Boolean Misrunning = false; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); MBTNPLaystart = (ImageButton) Findviewbyid (R.id.btn_play_start); Mbtnplaystart.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View arg0) {Handleplaybutton ();}}); Mviewpanbar = (ImageView) Findviewbyid (r.id.imageview2); Mpanlin = new Linearinterpolator (); Mpananim.setinterpolator ( Mpanlin); Mpananim.setanimationlistener (new Animationlistener () {@Override public void Onanimationst            Art (Animation Animation) {} @Override public void Onanimationend (Animation Animation) {            The lever starts to animate mviewpanbar.startanimation (Mbaroutanim);  } @Override public void Onanimationrepeat (Animation Animation) {}}); Mbarinanim = Animationutils.loadanimation (this, r.anim.rotate_45); Mbarinlin = new Linearinterpolator (); Mbarinanim.setfillafter (             true); Mbarinanim.setinterpolator (Mbarinlin); Mbarinanim.setanimationlistener (new Animationlistener () {@Override PubLIC void Onanimationstart (Animation Animation) {} @Override public void Onanimationend (A                        Nimation animation) {//Album Animation mviewpan.startanimation (Mpananim);  } @Override public void Onanimationrepeat (Animation Animation) {}}); Mbaroutanim = Animationutils.loadanimation (this, r.anim.rotate_d_45); Mbaroutlin = new Linearinterpolator (); Mbaroutanim.setfillafter (True); Mbaroutanim.setinterpolator (Mbaroutlin); Mbaroutanim.setanimationlistener (new            Animationlistener () {@Override public void Onanimationstart (Animation Animation) {} @Override public void Onanimationend (Animation Animation) {//Complete animation is finished Misrunnin            g = false;            Mbtnplaystart.setvisibility (view.visible); } @Override public void Onanimationrepeat (Animation Animation) {}        });} /** * handles the play button in the middle of the disc, which is to start playing music */private void Handleplaybutton () {if (Mviewpanbar! = null) {if (!misrunning) {Misrunni ng = true;//Lever enters the animation, the Start button is not visible mviewpanbar.startanimation (Mbarinanim); mbtnplaystart.setvisibility (view.invisible);}}                @Override public void OnPause () {mviewpan.clearanimation ();    Super.onpause (); }}



Running an instance:


SOURCE download

Favorite friends pay attention to me! Thank you



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Easy Tutorial-the 63rd shot (animation to achieve the album Playback interface)

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.