如何启动动画中的onCreate()中的机器人? [英] how to start Animation in onCreate() in android?

查看:161
本文介绍了如何启动动画中的onCreate()中的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了这样的它不工作?

 公共类AnimationActivity延伸活动{
            私人AnimationDrawable yourAnimation;
            @覆盖
            保护无效的onCreate(包savedInstanceState){
                // TODO自动生成方法存根
                super.onCreate(savedInstanceState);
                的setContentView(R.layout.animation);
                getIntentValues​​();
                最后的ImageView ImageView的=(ImageView的)findViewById(R.id.animation_iv);
                imageView.setBackgroundResource(R.drawable.loadinganim);
                yourAnimation =(AnimationDrawable)imageView.getBackground();
                yourAnimation.start();
    }
 

水库\绘制\ loading.xml

 < XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:单稳=假>
    <项目机器人:可绘制=@可绘制/ V1机器人:时间=160/>
    <项目机器人:可绘制=@可绘制/ V4机器人:时间=160/>
    <项目机器人:可绘制=@可绘制/ V7机器人:时间=160/>
    <项目机器人:可绘制=@可绘制/ V8机器人:时间=160/>
    <项目机器人:可绘制=@可绘制/ V9机器人:时间=160/>
    <项目机器人:可绘制=@可绘制/ V10机器人:时间=160/>
    <项目机器人:可绘制=@可绘制/ V11机器人:时间=160/>
   < /动画列表>
 

水库\布局\ animation.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:方向=垂直
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =FILL_PARENT
    >
< ImageView的
 机器人:ID =@ + ID / animation_iv
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =FILL_PARENT
 />
 

动画开始在ImageView的的onClick()。如果任何一个有想法帮助我。

解决方案

  view.setImageResource(R.anim.framer);
          view.post(新的Runnable(){
            公共无效的run(){
                AnimationDrawable animationDrawable =(AnimationDrawable)view.getDrawable();
                animationDrawable.start();
            }
          });
 

这工作对我试试吧!!!!

I have done like these it not working?

public class AnimationActivity extends Activity{
            private AnimationDrawable yourAnimation; 
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);
                setContentView(R.layout.animation);  
                getIntentValues();
                final ImageView imageView = (ImageView) findViewById(R.id.animation_iv);   
                imageView.setBackgroundResource(R.drawable.loadinganim);   
                yourAnimation = (AnimationDrawable) imageView.getBackground(); 
                yourAnimation.start();
    }

res\drawable\loading.xml

<?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/v1" android:duration="160" />  
    <item android:drawable="@drawable/v4" android:duration="160" />  
    <item android:drawable="@drawable/v7" android:duration="160" />  
    <item android:drawable="@drawable/v8" android:duration="160" />  
    <item android:drawable="@drawable/v9" android:duration="160" />  
    <item android:drawable="@drawable/v10" android:duration="160" />  
    <item android:drawable="@drawable/v11" android:duration="160" />  
   </animation-list>

res\layout\animation.xml

<?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/animation_iv"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 />

Animation is starting on imageView onClick().if any one have idea help me.

解决方案

          view.setImageResource(R.anim.framer);
          view.post(new Runnable() {
            public void run() {             
                AnimationDrawable animationDrawable = (AnimationDrawable)view.getDrawable();
                animationDrawable.start();
            }
          });

This worked for me try it !!!!

这篇关于如何启动动画中的onCreate()中的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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