集合动画+Hanlder倒计时跳转

 MainActivity


public class MainActivity extends Activity {
       
    TextView Mtv;
    Handler handler;
    int item=4;
    ImageView Mimg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找控件
     Mtv=(TextView) findViewById(R.id.Mtv);
     Mimg=(ImageView) findViewById(R.id.Mimg);
     //创建动画集合
     AnimationSet animationSet=new AnimationSet(true);
     //透明度  
    AlphaAnimation alphaAnimation=new AlphaAnimation(1f, 0.5f);
    animationSet.addAnimation(alphaAnimation);
    //缩放
    ScaleAnimation scaleAnimation=new  ScaleAnimation(1f,2f,1f,2f);
    animationSet.addAnimation(scaleAnimation);
    //旋转
    RotateAnimation rotateAnimation=new  RotateAnimation(0f,360,0.5f, 0.5f);
    animationSet.addAnimation(rotateAnimation);
    //平移
    TranslateAnimation translateAnimation=new TranslateAnimation(1f, 2f,1f, 2f);
    animationSet.addAnimation(translateAnimation);
    animationSet.setDuration(3000);
    animationSet.setFillAfter(true);
    //启动动画
     Mimg.startAnimation(animationSet);
     //Hanlder倒计时跳转
      handler=new Handler();
      handler.postDelayed(new Runnable() {
        
        @Override
        public void run() {
            // TODO Auto-generated method stub
        item--;    
        
        if (item==-1) {
        
        Intent intent=new Intent(MainActivity.this,Two.class);    
        
        startActivity(intent);
        }
            
        handler.postDelayed(this,1000);    
        
        Mtv.setText("倒计时:"+item+"秒");
            
        }
    },1000);    
        
        
    }

}

Layout布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <TextView
        android:id="@+id/Mtv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="跳转"
        android:textSize="20sp"/>
    <ImageView
      android:id="@+id/Mimg"  
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/ic_launcher"  
      android:layout_centerInParent="true"  
        
        
        />

</RelativeLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值