Giter VIP home page Giter VIP logo

kotlinspringanimation's Introduction

KotlinSpringAnimation

这是一个用kotlin编写的Android项目
尝试模仿Dribbble上的一个作品
注:使用前请安装Kotlin插件
需要25的编译环境,同时要求最低版本为16及以上,所以使用上还是有一些限制。如果有特殊需要,可以通过tools:overrideLibrary来做对应的兼容适配。
项目的gradle下添加

compile 'com.android.support:support-dynamic-animation:25.3.0'

项目最小编译版本应大于16

minSdkVersion 16

效果如下


声明该项目代码参考http://hoo.tips/2017/03/25/8cd3930b/?utm_source=tuicool&utm_medium=referral

Anroid原生代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
public class MainActivity extends AppCompatActivity {
private Button mSignUpBtn;
private ImageView mLeftLogoImg;
private ImageView mRightLogoImg;
private TextView mDescTitleTextView;
private LinearLayout mLettersLayout;
private LinearLayout mSignInLayout;
private ArrayList<SpringAnimation> mLetterAnims;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// hide the status ui.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
// get the screen height.
DisplayMetrics dm = getResources().getDisplayMetrics();
int screenHeight = dm.heightPixels;
// letters about 'Converse'
mLettersLayout = (LinearLayout) findViewById(R.id.letter_layout);
mLetterAnims = new ArrayList<>();
for (int i = 0; i < mLettersLayout.getChildCount(); i++) {
View letterView = mLettersLayout.getChildAt(i);
letterView.setTranslationY(screenHeight);
SpringAnimation letterAnimY = new SpringAnimation(letterView, SpringAnimation.TRANSLATION_Y, 0);
letterAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);
letterAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);
mLetterAnims.add(letterAnimY);
}
// text about 'Native messaging'
mDescTitleTextView = (TextView) findViewById(R.id.desc_title_textview);
mDescTitleTextView.setTranslationY(500f);
mDescTitleTextView.setAlpha(0f);
final SpringAnimation descTitleAnimY = new SpringAnimation(mDescTitleTextView, DynamicAnimation.TRANSLATION_Y, 0);
descTitleAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);
descTitleAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);
final ValueAnimator descTitleAlphaAnim = ObjectAnimator.ofFloat(0f, 1f);
descTitleAlphaAnim.setDuration(300);
descTitleAlphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mDescTitleTextView.setAlpha((Float) valueAnimator.getAnimatedValue());
}
});
// the button of sign up
mSignUpBtn = (Button) findViewById(R.id.sign_up_btn);
mSignUpBtn.setTranslationY(500f);
final SpringAnimation signUpBtnAnimY = new SpringAnimation(mSignUpBtn, SpringAnimation.TRANSLATION_Y, 0);
signUpBtnAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);
signUpBtnAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);
// the bottom text about 'Have an account? sign in'
mSignInLayout = (LinearLayout) findViewById(R.id.signin_layout);
mSignInLayout.setTranslationY(500f);
final SpringAnimation signInLayoutAnimY = new SpringAnimation(mSignInLayout, SpringAnimation.TRANSLATION_Y, 0);
signInLayoutAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);
signInLayoutAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);
// top logo by left
mLeftLogoImg = (ImageView) findViewById(R.id.left_logo_imageview);
mLeftLogoImg.setTranslationY(400f);
mLeftLogoImg.setAlpha(0f);
final SpringAnimation leftLogoAnimY = new SpringAnimation(mLeftLogoImg, SpringAnimation.TRANSLATION_Y, 0);
leftLogoAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);
leftLogoAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);
leftLogoAnimY.setStartVelocity(-2000);
// top logo by right
mRightLogoImg = (ImageView) findViewById(R.id.right_logo_imageview);
mRightLogoImg.setTranslationY(400f);
mRightLogoImg.setAlpha(0f);
final SpringAnimation rightLogoAnimY = new SpringAnimation(mRightLogoImg, SpringAnimation.TRANSLATION_Y, 0);
rightLogoAnimY.getSpring().setStiffness(SpringForce.STIFFNESS_VERY_LOW);
rightLogoAnimY.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY);
rightLogoAnimY.setStartVelocity(-2000);
final ValueAnimator logoAlphaAnim = ObjectAnimator.ofFloat(0f, 1f);
logoAlphaAnim.setDuration(600);
logoAlphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mLeftLogoImg.setAlpha((Float) valueAnimator.getAnimatedValue());
mRightLogoImg.setAlpha((Float) valueAnimator.getAnimatedValue());
}
});
mRightLogoImg.postDelayed(new Runnable() {
@Override
public void run() {
leftLogoAnimY.start();
mRightLogoImg.postDelayed(new Runnable() {
@Override
public void run() {
rightLogoAnimY.start();
}
}, 150);
mDescTitleTextView.postDelayed(new Runnable() {
@Override
public void run() {
descTitleAlphaAnim.setStartDelay(100);
descTitleAlphaAnim.start();
descTitleAnimY.start();
signUpBtnAnimY.start();
signInLayoutAnimY.start();
}
}, 300);
for (final SpringAnimation letterAnim : mLetterAnims) {
mLettersLayout.postDelayed(new Runnable() {
@Override
public void run() {
letterAnim.start();
}
}, 12 * mLetterAnims.indexOf(letterAnim));
}
logoAlphaAnim.start();
}
}, 1000);
}
}

此处仅结合kotlin在android中做了相对实现

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.