-
Notifications
You must be signed in to change notification settings - Fork 12
/
MainActivity.java
49 lines (40 loc) · 1.65 KB
/
MainActivity.java
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
/*
///Animating view properties with ViewPropertyAnimator
In this example ,we use a ViewPropertyAnimator to animate a view object.
*Call View.animate() and get a ViewPropertyAnimator object
* On it, you can call functions to animate properties like alpha ,
translation, rotation...
*IMPORTANT : This works on all classes inheriting the view class like TextViews
and Buttons.Android itself may be using things like these to create
those stunning effects in material themes.(DON'T QUOTE ME ON THIS THOUGH)
*API : 12
*/
package com.blikoon.app141;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity implements View.OnClickListener {
View viewToAnimate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.toggleButton);
button.setOnClickListener(this);
viewToAnimate = findViewById(R.id.theView);
}
@Override
public void onClick(View v) {
if (viewToAnimate.getAlpha() > 0f) {
//If the view is visible, slide it out to the right
viewToAnimate.animate().alpha(0f).translationX(1000f);
} else {
//If the view is hidden, do a fade-in in place
//Property Animations actually modify the view, so
// we have to reset the view's location first
viewToAnimate.setTranslationX(0f);
viewToAnimate.animate().alpha(1f);
}
}
}