zoukankan      html  css  js  c++  java
  • 使用xml方式定义补间动画

    在res下创建一个目录 anim目录

    public class MainActivity extends Activity {
    
        private ImageView iv;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            //执行我们的动画
            iv = (ImageView) findViewById(R.id.iv);
            
            //设置一个点击事件
            iv.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(), "哈哈 你点不到我", 1).show();
                }
            });
        }
    
    
        //点击按钮 实现iv 透明的效果  动画 
        public void click1(View v) { 
            Animation aa = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
            
            //iv开始执行动画 
            iv.startAnimation(aa);
            
        }
        
    
        //点击按钮 实现iv 执行一个旋转 动画 
        public void click2(View v) { 
            Animation ra = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
            
            //iv开始执行动画 
            iv.startAnimation(ra);
            
        }
        
        //点击按钮进行一个缩放动画
        public void click3(View v) { 
        
            Animation sa= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale);
            
            //iv开始执行动画 
            iv.startAnimation(sa);
        }
    
        //位移动画 
        public void click4(View v){
            Animation ta = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate);
             //开始动画
             iv.startAnimation(ta);
        }
        
        //动画一起飞
        public void click5(View v){
            Animation set = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.set);
            
            //最后一步 要记得 执行动画
            iv.startAnimation(set);
            
            
        }
    }
    alpha.xml
    <?xml version="1.0" encoding="utf-8"?>
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="2000"
        android:repeatMode="reverse"
        android:repeatCount="1"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
    
    </alpha>

    rotate.xml

    <?xml version="1.0" encoding="utf-8"?>
    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:duration="2000"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
    
    </rotate>
    scale.xml
    <?xml version="1.0" encoding="utf-8"?>
    <scale
        android:fromXScale="1.0"
        android:toXScale="2.0"
        android:fromYScale="1.0"
        android:toYScale="2.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatMode="reverse"
        android:repeatCount="1"
        android:duration="2000"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
    
    </scale>
    translate.xml
    <?xml version="1.0" encoding="utf-8"?>
    <translate
        android:fromXDelta="0%p"
        android:toXDelta="0%p"
        android:fromYDelta="0%p"
        android:toYDelta="20%p"
        
        android:fillAfter="true"
        android:duration="2000"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
        
        
        
    
    </translate>

    set.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set>
    
        <alpha
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="2000"
            android:fromAlpha="1.0"
            android:repeatCount="1"
            android:repeatMode="reverse"
            android:toAlpha="0.0" >
        </alpha>
    
        <rotate
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="2000"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="1"
            android:repeatMode="reverse"
            android:toDegrees="360" >
        </rotate>
    
        <scale
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="2000"
            android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="1"
            android:repeatMode="reverse"
            android:toXScale="2.0"
            android:toYScale="2.0" >
        </scale>
    
        <translate
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="2000"
            android:fillAfter="true"
            android:fromXDelta="0%p"
            android:fromYDelta="0%p"
            android:toXDelta="0%p"
            android:toYDelta="20%p" >
        </translate>
    
    </set>
  • 相关阅读:
    MVP福利利用Azure虚拟机玩Windows Server 2012
    负载均衡的基本算法
    RavenDB:基于Windows/.NET平台的NoSQL数据库
    使用Autofac在ASP.NET Web API上实现依赖注入
    Mono 3 的默认Gc是Sgen
    MSDN 杂志 Windows 8 特刊
    AggSharp Agg的.NET 移植
    使用谷歌翻译/微软翻译迅速使你的博客支持多国语言
    Service Bus for Windows server
    用Xwt构建跨平台应用程序[转载]
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6137894.html
Copyright © 2011-2022 走看看