30th: Android Animation (v)

Source: Internet
Author: User

Tian Jian, gentleman to self-improvement. --"Zhou Yi Hus Elephant"


This lecture: Frame-by- frames animation frame Animation

frame-by-frames animation frame animation that a frame of a frame of the link to play will become an animation, It 's very similar to the mechanism for putting movies.

Let's feel it through a sample, and the code is written in a stare.

The following is the Res/layout/activity_main.xml layout file:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:orientation= "vertical"    tools:context= "Com.example.text.mainactivity$placeholderfragment" > <imageview         android:id= "@+id/frame_image"        android:layout_width= "match_parent"        android:layout_ height= "Match_parent"        android:layout_weight= "1"/>    <button         android:id= "@+id/start"        Android:layout_width= "Match_parent"        android:layout_height= "wrap_content"        android:text= "RunFrame"/ >    <button         android:id= "@+id/stop"        android:layout_width= "match_parent"        android:layout_ height= "Wrap_content"        android:text= "Stopframe"/></linearlayout>

The following is a new Res/anim/frame.xml file

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "      android:oneshot=" false ">      <item android:drawable=" @drawable/b1 "android:duration=" 300 "/ >      <item android:drawable= "@drawable/b2" android:duration= "/> <item      android:drawable=" @ Drawable/b3 "android:duration=" "/>      <item android:drawable=" @drawable/b4 "android:duration="/>  

B1, B2, B3, B4 are four different little fox icons


The following is the Mainactivity.java main interface file:

public class Mainactivity extends Activity implements Onclicklistener {Private button start;private button stop;private Im Ageview IV; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); iv = (ImageView) Findviewbyid (r.id.frame_image); start = (Button) Findviewbyid (r.id.start); stop = (Button) Findviewbyid (r.id.stop); Start.setonclicklistener (this); Stop.setonclicklistener (This) ; Iv.setbackgroundresource (r.anim.frame);} @Overridepublic void OnClick (View v) {animationdrawable anim = (animationdrawable) iv.getbackground (); switch (V.getid () {Case r.id.start://invokes animation to draw an object's start Play Method Anim.start (); break;case r.id.stop://call the animation to draw the object's stop playback method anim.stop (); break;}}

The following are the results of the execution:



Ben said here, thank you!

30th: Android Animation (v)

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.