日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

animation of android (1)

發布時間:2024/1/17 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 animation of android (1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

android把動畫的模式分為:property animation,view animation,drawable animation.

view animation:給出動畫的起止狀態,并且通過一定的方式來是view動起來。這個動畫只能用于view。

幀動畫:是給出一組圖片,有drawable來展示動畫變化過程。

1.tweened animation

?layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".AnimationActivity" ><ImageViewandroid:id="@+id/animation_img"android:layout_width="150dp"android:layout_height="150dp"android:layout_centerInParent="true"android:src="@drawable/icon_follower" /><LinearLayoutandroid:id="@+id/action_items"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:orientation="horizontal" ><Buttonandroid:id="@+id/btn_alphaanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/alpha_animation" /><Buttonandroid:id="@+id/btn_rotateanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/rotate_animation" /><Buttonandroid:id="@+id/btn_scaleanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/scale_animation" /><Buttonandroid:id="@+id/btn_translationanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/scale_animation" /></LinearLayout></RelativeLayout>

activity:

package com.joyfulmath.animatatorsamples;import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.BounceInterpolator; import android.view.animation.LinearInterpolator; import android.view.animation.OvershootInterpolator; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.ImageView;public class AnimationActivity extends Activity implements OnClickListener{private static final String TAG = "animatatorsamples";Button mAlphaAnimation = null;Button mRotateAnimation = null;Button mScaleAnimation = null;Button mTranslationAnimation = null;ImageView mImage = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_animation_main);mAlphaAnimation = (Button) this.findViewById(R.id.btn_alphaanimation);mAlphaAnimation.setOnClickListener(this);mRotateAnimation = (Button) this.findViewById(R.id.btn_rotateanimation);mRotateAnimation.setOnClickListener(this);mScaleAnimation = (Button) this.findViewById(R.id.btn_scaleanimation);mScaleAnimation.setOnClickListener(this);mTranslationAnimation = (Button) this.findViewById(R.id.btn_translationanimation);mTranslationAnimation.setOnClickListener(this);mImage = (ImageView) this.findViewById(R.id.animation_img);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.animation, menu);return true;}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.btn_alphaanimation:startAlphaAnimation();break;case R.id.btn_rotateanimation:startRotateAnimation();break;case R.id.btn_scaleanimation:startScaleAnimation();break;case R.id.btn_translationanimation:startThanslationAnimation(); break;}}private void startRotateAnimation() {Log.i(TAG, "[startRotateAnimation]");//Animation.RELATIVE_TO_SELF the center of rotateAnimation rotateaAni = new RotateAnimation(0f, 360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);rotateaAni.setDuration(3000);rotateaAni.setFillAfter(true);rotateaAni.setInterpolator(new LinearInterpolator()); mImage.startAnimation(rotateaAni);}private void startAlphaAnimation() {Log.i(TAG, "[startAlphaAnimation]");AlphaAnimation alphaAni = new AlphaAnimation(1.0f, 0.5f);alphaAni.setDuration(3000);alphaAni.setFillAfter(true);alphaAni.setInterpolator(new OvershootInterpolator());alphaAni.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation arg0) {// TODO Auto-generated method stubLog.i(TAG, "[onAnimationStart]");}@Overridepublic void onAnimationRepeat(Animation arg0) {// TODO Auto-generated method stubLog.i(TAG, "[onAnimationRepeat]");}@Overridepublic void onAnimationEnd(Animation arg0) {// TODO Auto-generated method stubLog.i(TAG, "[onAnimationEnd]");}});mImage.startAnimation(alphaAni);}private void startScaleAnimation(){float fromX; //1.0f to 0.0ffloat toX; float fromY; float toY;int pivotXType; //where is the last place after scalefloat pivotXValue;int pivotYType; float pivotYValue; //Animation.ABSOLUTE, //the last place with X ordinate with absolute diff 20f//Animation.RELATIVE_TO_SELF, //specified dimension to self//Animation.RELATIVE_TO_PARENT. //specified dimension to parent move 100%=1f with diff (%parent diff)ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f // ,Animation.ABSOLUTE, 20f, Animation.RELATIVE_TO_PARENT, // 2f );//ScaleAnimation(float fromX, float toX, float fromY, float toY) 綾諱技Animation.ABSOLUTE,涓攛,y =0;scaleAnim.setDuration(3000);scaleAnim.setFillAfter(true);scaleAnim.setInterpolator(new OvershootInterpolator());mImage.startAnimation(scaleAnim);}private void startThanslationAnimation(){Log.i(TAG, "[startThanslationAnimation]");//Animation.ABSOLUTE where is the last point show place//the start x,y ordinate is the current place with translation TranslateAnimation anmit= new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0.1f,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT,0.2f,Animation.RELATIVE_TO_PARENT, 0.6f);anmit.setDuration(3000);anmit.setFillAfter(true);anmit.setInterpolator(new BounceInterpolator());mImage.startAnimation(anmit); }}

animation 是一種變換動畫,也就是實際的響應位置和大小并沒有變化,只是視圖上的變換。

這種動畫變換成本低,效率高。

這些類都繼承自android.view.animation.Animation

?2.animationset

view視圖動畫組合只用是一個view對象的多種狀態變換。

/*** Constructor to use when building an AnimationSet from code* * @param shareInterpolator Pass true if all of the animations in this set* should use the interpolator associated with this AnimationSet.* Pass false if each animation should use its own interpolator.*/public AnimationSet(boolean shareInterpolator) {setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK, shareInterpolator);init();}

如androidsdk源碼所示,shareInterpolator將決定使用每個animation的interpolator

還是animationset的變換方式。

animationset的變換只能一起播放,只有通過startoffset的方式可以模擬變換的順序。

3.android.view.animation.BaseInterpolator

變換方式:

末前支持的是:

AccelerateDecelerateInterpolator,  開始和結束變換慢,中間變換快速

AccelerateInterpolator,?       ??開始緩慢,然后加速

AnticipateInterpolator,        變換會有一個回調,也就是先向后變換,然后按照給定關鍵幀的方式變換。   

AnticipateOvershootInterpolator, ? ? ?An interpolator where the change starts backward then flings forward and overshoots the target value and finally goes back to the final value

BounceInterpolator,?        貝葉斯曲線

CycleInterpolator,          sin曲線

DecelerateInterpolator,       ?減速變化

LinearInterpolator,?         默認,線性變換

OvershootInterpolator,?      ?An interpolator where the change flings forward and overshoots the last value then comes back.

PathInterpolator          5.1新功能。可以自定義變換路徑方式。         

?

轉載于:https://www.cnblogs.com/deman/p/4357455.html

總結

以上是生活随笔為你收集整理的animation of android (1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。