編輯:關於Android編程
View動畫Set 使用
如果 set 標簽是父級標簽, 子標簽設置:android:fillAfter=”true” 是無效的
-
-
-
-
-
-
-
ObjectAnimator anim1 = ObjectAnimator.ofFloat(mViwe, "scaleX", 1.0f, 2f);
ObjectAnimator anim2 = ObjectAnimator.ofFloat(mViwe, "scaleY", 1.0f, 2f);
ObjectAnimator anim3 = ObjectAnimator.ofFloat(mViwe, "x", cx, 0f);
ObjectAnimator anim4 = ObjectAnimator.ofFloat(mViwe, "x", cx);
ObjectAnimator anim5 = ObjectAnimator.ofFloat(mViwe, "scaleX", 2f, 1.0f);
ObjectAnimator anim6 = ObjectAnimator.ofFloat(mViwe, "scaleY", 2f, 1.0f);
/**
* anim1,anim2,anim3同時執行 anim4接著執行
*/
AnimatorSet animSet = new AnimatorSet();
animSet.play(anim1).with(anim2);
animSet.play(anim2).with(anim3);
animSet.play(anim4).after(anim3);
animSet.play(anim5).with(anim6);
animSet.play(anim6).after(anim4);
animSet.setDuration(100);
//插值器,增加動畫特效
//animSet.setInterpolator(new LinearInterpolator());
//兩個動畫同時執行
//animSet.playTogether(anim1, anim2);
//順序執行
//animSet.playSequentially(anim1,anim2);
animSet.start();
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 0, 1f);
PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 0, 1f);
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mView, pvhX, pvhY, pvhZ).setDuration(2000);
animator.start();
/**
* 第二個參數 propertyName 介紹:
* translationX 相對view自身開始X軸位移
* translationY 相對view自身開始Y軸位移
* x 在屏幕X軸像素開始位移
* y 在屏幕Y軸像素開始位移
* alpha 透明動畫
* rotation 相對view中心開始旋轉
* rotationX 相對view X軸開始旋轉
* rotationY 相對view Y軸開始旋轉
* scaleY 相對view Y軸開始縮放
* scaleX 相對view X軸開始縮放
*/
ObjectAnimator anim = ObjectAnimator.ofFloat(view, "rotation", 1.0F, 360F).setDuration(1000);
anim.setRepeatCount(-1);
anim.start();
// 由於ofFloat 是可變參數,我們也可以這樣玩:
// ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 1.0f, 0.85f, 0.65f, 0.45f, 0.35f, 0.15f).setDuration(2000);
// anim.start();
/**
* 即使在第二個參數,沒有指定,屬性動畫的名稱,我們還可以在animator.addUpdateListener,指定動畫的類型
* eg:
* Integer value= (Integer)animation.getAnimatedValue();
* view.setTranslationY(value);
*/
ObjectAnimator animator=ObjectAnimator.ofInt(mView, "lxcay", 800);
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer value= (Integer)animation.getAnimatedValue();
mView.setAlpha(value);
mView.setScaleX(value);
mView.setScaleY(value);
mView.setTranslationX(value);
mView.setTranslationY(value);
}
});
/**
* 設置插值器,插值器,增加動畫特效
*/
animator.setInterpolator(new BounceInterpolator());
animator.setDuration(3000);
animator.start();
不需要指定 propertyName 用法跟 ObjectAnimator 使用差不多,但是必須結合
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {}
});
一起使用,不然無效;
// 開始顏色為色
int startColor = 0xffff0000;
// 終止顏色為綠色
int endColor = 0xff00ff00;
ValueAnimator animator = ValueAnimator.ofArgb(startColor, endColor);
animator.setTarget(mTextView);
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int color = (Integer) animation.getAnimatedValue();
mTextView.setBackgroundColor(color);
}
});
animator.setDuration(3000);
animator.start();
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int mScreenHeight = outMetrics.heightPixels;
ValueAnimator animator = ValueAnimator.ofFloat(0, mScreenHeight - mView.getHeight() * 4);
animator.setTarget(mBlueBall);
animator.setDuration(1000).start();
animator.setInterpolator(new OvershootInterpolator()/*AnimationUtils.loadInterpolator(this, android.R.anim.overshoot_interpolator)*/);
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (Float) animation.getAnimatedValue();
// mBlueBall.setScaleX(value);
// mBlueBall.setScaleY(value);
// mBlueBall.setTranslationX(value);
// mBlueBall.setAlpha(value);
mBlueBall.setTranslationY(value);
}
});
ObjectAnimator animation = ObjectAnimator.ofFloat(mBlueBall, "alpha", 0.5f);
animation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Log.e(TAG, "onAnimationEnd");
ViewGroup parent = (ViewGroup) mView.getParent();
if (parent != null){
//刪除動畫
parent.removeView(mView);
}
}
});
animation.start();
3.1系統及以上:
ViewPropertyAnimator的使用
mTextView.animate().x(500).y(500).setDuration(5000).setInterpolator(new BounceInterpolator());
炒雞簡單,有木有!
雖然代碼裡面沒有調用start(),但是在創建好動畫後會在內部隱士調用。start();
超實用的Android手勢鎖制作實例教程
今天偶遇以github上gesturelock關於手勢鎖的一個例子(有興趣的去搜索下看看),於是下載下來研究,無奈基本沒有注釋,代碼上存在一些問題(當設置gravity=
Android Studio(二)導入eclipse項目
一、導入單個Eclipse項目 1.在Eclipse中導出包含有gradle的項目,操作如下: 如果操作中出現finish按鈕是灰色的,將force overridin
Android app啟動時黑屏或者白屏的原因及解決辦法
1、產生原因其實顯示黑屏或者白屏實屬正常,這是因為還沒加載到布局文件,就已經顯示了window窗口背景,黑屏白屏就是window窗口背景。示例:2、解決辦法通過設置設置S
Android使用開源框架ANDROID-IMAGE-INDICATOR實現圖片輪播部署
之前的博文中有介紹關於圖片輪播的實現方式,分別為(含超鏈接):1、《Android中使用ViewFlipper實現屏幕切換》2、《Android中使用ViewPager實