码迷,mamicode.com
首页 > 其他好文 > 详细

使用属性动画简单实现view飞入效果

时间:2015-03-06 15:31:12      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

比较简单的效果,可以用来菜单飞入之类,作为记录吧,

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;
    }
}

  

直接上代码

使用属性动画简单实现view飞入效果

标签:

原文地址:http://www.cnblogs.com/songsyl1207/p/4318103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!