逐幀動畫(Frame-by-frame Animations),逐幀動畫

來源:互聯網
上載者:User

逐幀動畫(Frame-by-frame Animations),逐幀動畫

1.這一類動畫可以建立一個Drawable序列,這些Drawable可以按照指定的時間間歇一個一個的顯示.

 xml定義方法

1 <animation-list xmlns:android="http://schemas.android.com/apk/res/android"2     android:oneshot="false">3  <item android:drawable="tu1" android:duration="200"/>4  <item android:drawable="tu2" android:duration="200"/>5  <item android:drawable="tu3" android:duration="200"/>6 </animation-list>

2.逐幀動畫是在drawable下建立的一種圖片,根節點是animation-list(動畫列表),oneshot屬性工作表示是否只播放一次,內部用item節點聲明一個個的動畫。

 其中drawable指明使用的圖片,duration屬性這一動畫顯示的時間,單位毫秒。

   然後可以將其當做背景圖片來使用

1 <TextView2     android:id="@+id/main_tv"3     android:layout_width="100dp"4     android:layout_height="100dp"5     android:background="@drawable/animation_list"/>

3.然開在代碼中開始播放動畫即可

1 ((AnimationDrawable)img.getBackground()).start();

 

 

 

//=============

  執行個體:幀動畫

:

          

 

Demo1\app\src\main\res\drawable\anim_frame.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 3     android:oneshot="false"> 4     <item 5         android:drawable="@drawable/aa" 6         android:duration="500" /> 7     <item 8         android:drawable="@drawable/bb" 9         android:duration="500" />10     <item11         android:drawable="@drawable/cc"12         android:duration="500" />13     <item14         android:drawable="@drawable/dd"15         android:duration="500" />16     <item17         android:drawable="@drawable/ee"18         android:duration="500" />19     <item20         android:drawable="@drawable/ff"21         android:duration="500" />22 </animation-list>

Demo1\app\src\main\res\layout\activity_main.xml

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     tools:context=".MainActivity"> 6  7     <ImageView 8         android:id="@+id/main_img" 9         android:layout_width="100dp"10         android:layout_height="180dp"11         android:layout_centerHorizontal="true"12         android:layout_centerVertical="true"13         android:background="@drawable/anim_frame"/>14 </RelativeLayout>

Demo1\app\src\main\java\com\ly\demo1\MainActivity.java

 1 package com.ly.demo1; 2  3 import android.app.Activity; 4 import android.graphics.drawable.AnimationDrawable; 5 import android.os.Bundle; 6 import android.widget.ImageView; 7  8 public class MainActivity extends Activity { 9     private ImageView img;10 11     @Override12     protected void onCreate(Bundle savedInstanceState) {13         super.onCreate(savedInstanceState);14         setContentView(R.layout.activity_main);15         img = (ImageView) findViewById(R.id.main_img);16         ((AnimationDrawable)img.getBackground()).start();17     }18     19 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.