android animation
VIEW ANIMATION , PROPERTY ANIMATION 둘다 같은 작업을 수행할수있다. 차이점이 있다면 view animation의 경우 animation후에 보이는 것은 변경되었을지 모르지만 실제 존재하는 위치는 같으므로 클릭을 한다고 하면 본래 위치에 클릭해야 해당 view가 이벤트를 받아들이게 된다.Their state changes but their property does not change.
ObjectAnimator를 이용하는 것은 property animation이다. ObjectAnimator is a subclass of ValueAnimator
TranslateAnimation, RotateAnimation, ScaleAnimation, AlphaAnimation 을 이용하는 것은 view animation이다.
When using View Animations, use XML instead of doing it programmatically. Using XML files, it is more readable and can be shared among other views.
참조 https://youtu.be/_UWXqFBF86U?t=204
basics 3 types of Animations:
Property Animations — They are used to alter property of objects (Views or non view objects). We specify certain properties(like translateX, TextScaleX) of the objects to change. Various characteristics of animation which can be manipulated are animation duration, whether to reverse it and for how many times we want to repeat the animation etc. They were introduced in Android 3.0 (API level 11).
View Animations — They are used to do simple animations like changing size, position, rotation, control transparency. They are easy to build and are very fast but have their own constraints. For eg — Their state changes but their property does not change. View animations will be covered in part 2.
Drawable Animations — This is used to do animation using drawables. An XML file specifying various list of drawables is made which are run one by one just like a roll of a film. This is not much used so I won’t cover it.
property animation
- ObjectAnimator를 이용한다. ( ValueAnimator를 기반으로 한다 )
- AnimatorSet 를 이용 여러 view들의 animations을 동시에 진행가능하다. ( with()를 사용하기도한다 )
- 하나의 view에 대한 여러 animation을 동시에 진행하는 경우 ViewPropertyAnimator 를 이용한다.
animateTextView.animate().rotation(360f).y(500f).setDuration(2000);
View Animation
Tween Animation — These are the animations applied on a view which is responsible for scaling, translating, rotating or fading a view (either together or one by one).
Frame Animation — These animations are applied using various drawables. In this, we just have to specify a list of drawables in the XML code and the animation runs just like frames of a video.
View Animations are not much used because the same thing can be using ViewPropertyAnimator object which is much faster and readable. Frame animation is similar to Drawable Animation. The more important thing is to understand the new Transition framework which is much useful and provide beautiful animations.
ValueAnimator는 기본적으로 특정범위의 값들을 순차적으로 생성하는 기능을 하고 이 생성된 값을 view의 속성값으로 할당함으로써 애니메이션을 구현한다.
참조 영상)
https://youtu.be/jwdTNaddHHs
https://youtu.be/AaovTqdqYHY?t=288
API 21이후에 추간된 ANIMATION
Shared Element Transitions
Activity Transitions
Circular Reveal
Shared Element Transitions
http://blogs.quovantis.com/how-to-apply-shared-element-transitions-in-android/
참고자료)
view animation brief explanation
https://youtu.be/_UWXqFBF86U
A beginners guide to implement Android Animations — Part 1 (2 part series)
https://medium.com/@shubham.bestfriendforu/a-beginners-guide-to-implement-android-animations-part-1-2-part-series-b5fce1fc85
VIEW ANIMATION VS PROPERTY ANIMATION IN ANDROID
https://mahbubzaman.wordpress.com/2015/06/03/view-animation-vs-property-animation-in-android/
Sometimes we need to animate some view in our application. Here is a sample code for translate a view over x axis from its location.
Button bt;
bt = (Button) findViewById(R.id.bt);
bt.setOnClickListener(this);
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 300, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF);
animation.setDuration(1000);
animation.setFillAfter(true);
bt.setAnimation(animation);
But the problem of this code is if you want to click this button after animate you can not, why lets read the documentation from android developer site
disadvantage of the view animation system is that it only modified where the View was drawn, and not the actual View itself. For instance, if you animated a button to move across the screen, the button draws correctly, but the actual location where you can click the button does not change, so you have to implement your own logic to handle this.
more
To solve this issue we will use ObjectAnimator class to animate our view.
ObjectAnimator animXNext = ObjectAnimator.ofFloat(bt, "translationX", Animation.RELATIVE_TO_SELF, 300);
animXNext.setDuration(1000);
animXNext.start();
Now you can click on the button. Enjoy
0 notes
Path path;
p.seStrokeWidth(3);
p.setStyle(Paint.Style.STROKE);
p.setStrokeJoin(Paint.Join.ROUND);
path = new Path();
canvas.drawPath(path, p);
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(event.getX(), eventgetY());
break;
case MotionEvent.ACTION_MOVE:
path.lineTo(event.getX(), event.getY());
break;
case MotionEvent.ACTION_UP:
path.lineTo(event.getX(), event.getY());
break;
}
draw(getHolder());
return true;
}
loadAnimationメソッド
public static Animation loadAnimation(Context context, int id)
startAnimationメソッド
public void startAnimation(Animation animation)
android:startOffset="3000"
AlphaAnimationクラス
public AlphaAnimation(float fromAlpha, float toAlpha)
RoateAnimationクラス
public RoateAnimation(float fromDegress, float toDegrees, float pivotX, float pivotY)
AnimationSetクラス
public AnimationSet(boolean shareInterpolator)
addAnimationメソッド
public void addAimation(Animation a)
android:interpolator="@android:anim/accelerate_interpolator"
setBackgroundResourceメソッド
public void setBackgroundResource(int resid)
addFrameメソッド
public void addFrame(Drawable frame, int duration)
setOneShotメソッド
public void setOneShot(boolean oneShot)
loadAnimatiorメソッド
static Animator loadAnimator(Context context, int id)
ofxxxメソッド
ObjectAnimator ofXxxxx(Object target, String prop, float... values)
playSequentially/playTogetherメソッド
public void playSequentially(Animator... items)
public void playTogether(Animator... itmes)
style="@style/TextStyle1"
android:theme="@style/WingsTheme"
android:theme="@style/WingsTheme"
1 note
·
View note
package com.example.splashsample;
import android.app.Activity;
import android.content.Intent;
import android.content.SharePreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
impotr android.view.animation.Animation.AnimationListener;
public class SplashActivity extends Activity {
private static final String TAG = "SplashActivity";
private View[] labels = new View[3];
private AlphaAnimation animation = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
animation = new AlphaAnimation(0.1f, 1);
animation.setAnimationListener(new AnimationListener(){
//
//
public void onAnimationEnd(Animation animation) {
//
labels[animationNo].setAnimation(null);
//
++animationNo;
if(animationNo < labels.length){
//
labels[animationNo].setAlpha(1);
//
labels(animationNo].startAnimation(animation);
}
}
public void onAnimationRepeat(Aimation animation) {
}
public void onAnimationStart(Animation animation) {
}
setContentView(R.layout.activity_splash);
//
label[0] = findviewById(R.id.textView2);
label[1] = findViewById(R.id.textView3);
label[2] = findViewById(R.id.textView4);
for(int i = 1; i < labels.length; ++i){
labels[i].setAlpha(0);
}
labels[0].startAnimation(animation);
//
//
new Tread(new Runnable(){
public void run(){
//
for(int void run(){
//
for(int i = 0; i < 10; ++i){
Log.v(TAG, "processing:" + i);
try{
Thread.sleep(1000);
}catch(Exception e){
}
}
//
SharePreferences prefs = getSharePreferences("settings",
Activity.MODE_PRIVATE);
SharePreferences.Editor editor = prefs.edit();
//
for(int i = 0; i < labels.length; ++i){
labels[i].setAnimation(null);
}
//
startActivity(new Intent(SplashActivity.this,
MainActivity.class));
//
SplashActivity.this.finish();
}
}).start();
}
}
0 notes