Skip to content

Commit

Permalink
添加属性动画
Browse files Browse the repository at this point in the history
  • Loading branch information
xingchenfengn committed Nov 21, 2016
1 parent 53de605 commit 1295b78
Show file tree
Hide file tree
Showing 42 changed files with 464 additions and 15 deletions.
2 changes: 1 addition & 1 deletion animationdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.xingzhiqiao.animationdemo"
minSdkVersion 9
minSdkVersion 11
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand Down
5 changes: 4 additions & 1 deletion animationdemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".EnterActiviy"
android:theme="@style/AppTheme.LaunchStyle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -17,6 +19,7 @@
</activity>
<activity android:name=".PropAnimActivity"></activity>
<activity android:name=".ViewAnimationActivity"></activity>
<activity android:name=".MainActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.xingzhiqiao.animationdemo;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;

/**
* Created by xingzhiqiao on 2016/11/17.
*/

public class EnterActiviy extends AppCompatActivity {


private ImageView mBg;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter);
mBg = (ImageView) findViewById(R.id.bg_boy);


AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(mBg, "scaleX", 1, 1.5f),
ObjectAnimator.ofFloat(mBg, "scaleY", 1, 1.5f));
set.setDuration(2000);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
Intent intent = new Intent(EnterActiviy.this, MainActivity.class);
EnterActiviy.this.startActivity(intent);
finish();
}
});
set.setInterpolator(new AccelerateDecelerateInterpolator());
set.start();

}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package com.xingzhiqiao.animationdemo;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;

/**
* 属性动画
Expand All @@ -10,12 +22,175 @@

public class PropAnimActivity extends AppCompatActivity {

private ImageView mBoyImg;
private Button mPropBtn;
private Button mTv;
private Button freedownBtn, paowuxianBtn;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prop);

mBoyImg = (ImageView) findViewById(R.id.prop_img);
mPropBtn = (Button) findViewById(R.id.prop_btn);
mTv = (Button) findViewById(R.id.prop_tv);

mBoyImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// ObjectAnimator.ofFloat(mBoyImg, "translationY", mBoyImg.getHeight()).start();
ObjectAnimator.ofFloat(mBoyImg, "translationY", -mBoyImg.getHeight()).start();
}
});
mPropBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//背景色在3s内实现从0xFFFF8080到0xFF8080FF的渐变
// ValueAnimator colorAnimator = ObjectAnimator.ofInt(mPropBtn, "backgroundColor",/*Red*/0xFFFF8080,/*Blue*/0xFF8080FF);
// colorAnimator.setDuration(3000);
// colorAnimator.setEvaluator(new ArgbEvaluator());
// colorAnimator.setRepeatCount(ValueAnimator.INFINITE);
// colorAnimator.setRepeatMode(ValueAnimator.REVERSE);
// colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
// //持有一个IntEvaluator对象,方便下面估值的时候使用
// private IntEvaluator mEvaluator = new IntEvaluator();
//
// @Override
// public void onAnimationUpdate(ValueAnimator valueAnimator) {
// //获得当前动画的进度值,整形,1-100之间
// int currentValue = (int) valueAnimator.getAnimatedValue();
// Log.d("TAG", "current value" + currentValue);
// //获得当前进度占整个动画的过程的比例,浮点,0-1之间
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {
// float fraction = valueAnimator.getAnimatedFraction();
// Log.d("TAG", "fraction" + fraction);
// }
//
//
// }
// });
// colorAnimator.start();

}
});

mPropBtn.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {


AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(mPropBtn, "rotationX", 0, 360),
ObjectAnimator.ofFloat(mPropBtn, "rotationY", 0, 180),
ObjectAnimator.ofFloat(mPropBtn, "rotation", 0, -90),
ObjectAnimator.ofFloat(mPropBtn, "translationX", 0, 180),
ObjectAnimator.ofFloat(mPropBtn, "translationY", 0, 360),
ObjectAnimator.ofFloat(mPropBtn, "scaleX", 1, 1.5f),
ObjectAnimator.ofFloat(mPropBtn, "scaleY", 1, 0.5f),
ObjectAnimator.ofFloat(mPropBtn, "alpha", 1, 0.25f, 1));
animatorSet.setDuration(5000).start();
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
}

@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
}

@Override
public void onAnimationRepeat(Animator animation) {
super.onAnimationRepeat(animation);
}

@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
}

@Override
public void onAnimationPause(Animator animation) {
super.onAnimationPause(animation);
}

@Override
public void onAnimationResume(Animator animation) {
super.onAnimationResume(animation);
}
});

return true;
}
});

mTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ObjectAnimator.ofInt(mTv, "width", 500).setDuration(5000).start();
}
});


freedownBtn = (Button) findViewById(R.id.free_down);
paowuxianBtn = (Button) findViewById(R.id.paowuxian);


freedownBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

freeDown();
}
});
paowuxianBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
paowuxian();
}
});

}

private void freeDown() {
WindowManager manager = getWindowManager();
int screenheight = manager.getDefaultDisplay().getHeight();
ObjectAnimator.ofFloat(mPropBtn, "translationY", 0, screenheight - mPropBtn.getHeight()).start();

}

private void paowuxian() {

ValueAnimator valueAnimator = new ValueAnimator();
valueAnimator.setDuration(3000);
valueAnimator.setTarget(mPropBtn);
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.setObjectValues(new PointF(0, 0));
valueAnimator.setEvaluator(new TypeEvaluator<PointF>() {
@Override
public PointF evaluate(float v, PointF pointF, PointF t1) {
PointF pointf = new PointF();
pointf.x = 200 * v * 3;
pointf.y = 0.5f * 400 * 3 * v * 3 * v;

return pointf;
}

});
valueAnimator.start();
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
PointF pointf = (PointF) valueAnimator.getAnimatedValue();
mPropBtn.setX(pointf.x);
mPropBtn.setY(pointf.y);
}
});

}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.xingzhiqiao.animationdemo;

import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;

/**
* 视图动画
Expand All @@ -18,13 +23,18 @@ public class ViewAnimationActivity extends AppCompatActivity {


private ImageView mImg;
private ImageView mLoading;
private ListView mLv;
private Button enterBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);




mImg = (ImageView) findViewById(R.id.boy);
mImg.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -33,20 +43,55 @@ public void onClick(View view) {
mImg.startAnimation(animation);
}
});

mLoading = (ImageView) findViewById(R.id.frameImg);
mLoading.setBackgroundResource(R.drawable.refresh_loading);
AnimationDrawable drawable = (AnimationDrawable) mLoading.getBackground();
drawable.start();

mLv = (ListView) findViewById(R.id.lv);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_item);
LayoutAnimationController controller = new LayoutAnimationController(animation);
controller.setDelay(0.5f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
mLv.setLayoutAnimation(controller);

enterBtn = (Button) findViewById(R.id.enter_btn);
enterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActiviy();
}
});


//
}

private void StartAnim() {
private void startAnim() {
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(300);
mImg.startAnimation(alphaAnimation);

TranslateAnimation translateAnimation = new TranslateAnimation(0,100,0,100);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 100, 0, 100);
mImg.startAnimation(translateAnimation);
//...

}

public void startActiviy() {
Intent intent = new Intent(this, EnterActiviy.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);
}

@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);
}



}

Expand Down
14 changes: 14 additions & 0 deletions animationdemo/src/main/res/anim/anim_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:interpolator="@android:anim/decelerate_interpolator"
android:shareInterpolator="true">

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<scale
android:fromYScale="0.5"
android:toYScale="1.2" />

</set>
5 changes: 5 additions & 0 deletions animationdemo/src/main/res/anim/anim_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/anim_item"
android:animationOrder="normal"
android:delay="0.5"></layoutAnimation>
Loading

0 comments on commit 1295b78

Please sign in to comment.