标签:
比较简单的效果,可以用来菜单飞入之类,作为记录吧,
package com.test.animation; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import com.nineoldandroids.animation.AnimatorSet; import com.nineoldandroids.animation.ObjectAnimator; import java.util.ArrayList; import java.util.List; /** * Created by song on 2015/3/5. */ public class AnimationContextMenuActivity extends Activity{ List<Button> items = new ArrayList<Button>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initView(); } private void initView() { LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); for (int i = 0; i < 5; i++) { Button btn = new Button(this); btn.setText("btn" + i); btn.setAlpha(0); items.add(btn); layout.addView(btn,params); } setContentView(layout); // showMenu();//顺序飞入 showMenu1();//延迟飞入 } private void showMenu() { AnimatorSet set=new AnimatorSet(); set.playSequentially(getAnimation(items.get(0)), getAnimation(items.get(1)), getAnimation(items.get(2)), getAnimation(items.get(3)), getAnimation(items.get(4))); set.start(); } private AnimatorSet getAnimation(View view){ AnimatorSet set=new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(view, "translationX", -100, 0).setDuration(500),ObjectAnimator.ofFloat(view,"alpha",0,1).setDuration(500)); return set; } private void showMenu1() { AnimatorSet set=new AnimatorSet(); set.playTogether(getAnimation1(items.get(0)), getAnimation1(items.get(1)), getAnimation1(items.get(2)), getAnimation1(items.get(3)), getAnimation1(items.get(4))); set.start(); } int i=0; private AnimatorSet getAnimation1(View view){ AnimatorSet set=new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(view, "translationX", -100, 0).setDuration(500),ObjectAnimator.ofFloat(view,"alpha",0,1).setDuration(500)); set.setStartDelay((i += 1) * 100); return set; } }
直接上代码
标签:
原文地址:http://www.cnblogs.com/songsyl1207/p/4318103.html