加入收藏 | 设为首页 | 会员中心 | 我要投稿 三明站长网 (https://www.0598zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Android开发:Frame-By-Frame Animations的使用技巧

发布时间:2021-11-25 15:41:19 所属栏目:教程 来源:互联网
导读:Android开发:Frame-By-Frame Animations的使用方法 ?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/nv1 android:duration=500 / item

Android开发:Frame-By-Frame Animations的使用方法
 
<?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/nv1" android:duration="500" />  
    <item android:drawable="@drawable/nv2" android:duration="500" />  
    <item android:drawable="@drawable/nv3" android:duration="500" />  
    <item android:drawable="@drawable/nv4" android:duration="500" />  
</animation-list>  
首先是建在res的drawable目录下面建一个 anmi_nv.xml文件,再写上上面的配置。
 
下面是MainActivity:
 
package mars.animations05;  
  
import android.app.Activity;  
import android.graphics.drawable.AnimationDrawable;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
import android.widget.ImageView;  
  
public class MainActivity extends Activity {  
    private Button button = null;  
    private ImageView imageView = null;  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        imageView = (ImageView)findViewById(R.id.imageViewId);  
        button = (Button)findViewById(R.id.buttonId);  
        button.setOnClickListener(new ButtonListener());  
    }  
      
    private class ButtonListener implements OnClickListener{  
  
        public void onClick(View v) {  
            imageView.setBackgroundResource(R.drawable.anim_nv);  
            AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();  
            animationDrawable.start();  
        }  
          
    }  
}  
main.xml:
 
<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical" android:layout_width="fill_parent"  
    android:layout_height="fill_parent">  
  
    <Button android:id="@+id/buttonId" android:layout_width="fill_parent"  
        android:layout_height="wrap_content" android:layout_alignParentBottom="true"  
        android:text="测试动画效果" />  
  
          
    <LinearLayout android:orientation="vertical"  
        android:layout_width="fill_parent" android:layout_height="fill_parent">  
  
        <ImageView android:id="@+id/imageViewId"  
            android:layout_width="wrap_content" android:layout_height="wrap_content"  
            android:layout_centerInParent="true" android:layout_marginTop="100dip"  
            />  
    </LinearLayout>  
</RelativeLayout>  

(编辑:三明站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!