我需要简单的机器人动画的例子 [英] I need simple Android animation examples

查看:451
本文介绍了我需要简单的机器人动画的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给我与XML的简单机器人动画的例子。我是新来的Andr​​oid,我需要明确的解释。

Please give me simple Android animation examples with XML. I'm new to Android, and I need clear explanations.

推荐答案

试试这个,希望大家觉得有趣..

Try this hope you find interesting ..

下面是code的活动......

here is code for activity ...

package test.example;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class AminationDemo extends Activity implements OnClickListener {

    ImageView img;

    Button strtbtn,stpbtn;

    AnimationDrawable mAnimation;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        img = (ImageView) findViewById(R.id.iv);

        BitmapDrawable frame0 = (BitmapDrawable)getResources().getDrawable(R.drawable.f0);
        BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.f1);
        BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.f2);
        BitmapDrawable frame3 = (BitmapDrawable)getResources().getDrawable(R.drawable.f3);
        BitmapDrawable frame4 = (BitmapDrawable)getResources().getDrawable(R.drawable.f4);
        BitmapDrawable frame5 = (BitmapDrawable)getResources().getDrawable(R.drawable.f5);

        int reasonableDuration = 750;
        mAnimation = new AnimationDrawable();
        mAnimation.addFrame(frame0, reasonableDuration);
        mAnimation.addFrame(frame1, reasonableDuration);
        mAnimation.addFrame(frame2, reasonableDuration);
        mAnimation.addFrame(frame3, reasonableDuration);
        mAnimation.addFrame(frame4, reasonableDuration);
        mAnimation.addFrame(frame5, reasonableDuration);

        img.setBackgroundDrawable(mAnimation);        
        strtbtn = (Button) findViewById(R.id.strtbtn);
        strtbtn.setOnClickListener(this);
        stpbtn = (Button) findViewById(R.id.stpbtn);
        stpbtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

      if(v.getId()== R.id.strtbtn){

          mAnimation.start();
          mAnimation.setOneShot(false);
      }
      else
        mAnimation.stop();
    }  
}

布局主...

the layout main ...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageView  
    android:id="@+id/iv"
    android:layout_width="400dp" 
    android:layout_height="250dp" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button 
        android:layout_height="wrap_content" 
        android:id="@+id/strtbtn" 
        android:layout_width="wrap_content" 
        android:text="start"
        />    
    <Button 
        android:layout_height="wrap_content" 
        android:id="@+id/stpbtn" 
        android:layout_width="wrap_content" 
        android:text="stop"
        />    
</LinearLayout>
</LinearLayout>

下面是例如帧,也可以创建自己的...(放在绘制名为F0,F1,...)

Here are frames for example or you can create your own ...(put in drawable with name f0,f1,...)

这篇关于我需要简单的机器人动画的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆