【移動應用開發(fā)技術】Android動畫知識有哪些_第1頁
【移動應用開發(fā)技術】Android動畫知識有哪些_第2頁
【移動應用開發(fā)技術】Android動畫知識有哪些_第3頁
【移動應用開發(fā)技術】Android動畫知識有哪些_第4頁
【移動應用開發(fā)技術】Android動畫知識有哪些_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

【移動應用開發(fā)技術】Android動畫知識有哪些

//初始化

Animation

alphaAnimation

=

new

AlphaAnimation(0.1f,

1.0f);

//設置動畫時間

alphaAnimation.setDuration(3000);

this.startAnimation(alphaAnimation);

Animation

rotateAnimation

=

new

RotateAnimation(0f,

360f);

rotateAnimation.setDuration(1000);

this.startAnimation(rotateAnimation);

//初始化

Animation

scaleAnimation

=

new

ScaleAnimation(0.1f,

1.0f,0.1f,1.0f);

//設置動畫時間

scaleAnimation.setDuration(500);

this.startAnimation(scaleAnimation);

//初始化

nimation

translateAnimation

=

new

TranslateAnimation(0.1f,

100.0f,0.1f,100.0f);

//設置動畫時間

translateAnimation.setDuration(1000);

this.startAnimation(translateAnimation);

//初始化

Translate動畫

translateAnimation

=

new

TranslateAnimation(0.1f,

100.0f,0.1f,100.0f);

//初始化

Alpha動畫

alphaAnimation

=

new

AlphaAnimation(0.1f,

1.0f);

//動畫集

AnimationSet

set

=

new

AnimationSet(true);

set.addAnimation(translateAnimation);

set.addAnimation(alphaAnimation);

//設置動畫時間

(作用到每個動畫)

set.setDuration(1000);

this.startAnimation(set);

<set

android:interpolator="@android:anim/accelerate_interpolator">

</set>

<?xml

version="1.0"

encoding="utf-8"?>

<InterpolatorName

xmlns:android="/apk/res/android"

android:attribute_name="value"

/>

<?xml

version="1.0"

encoding="utf-8"?>

<overshootInterpolator

xmlns:android="/apk/res/android"

android:tension="7.0"/>

<scale

xmlns:android="/apk/res/android"

android:interpolator="@anim/my_overshoot_interpolator"

android:fromXScale="1.0"

android:toXScale="3.0"

android:fromYScale="1.0"

android:toYScale="3.0

android:pivotX="50%"

android:pivotY="50%"

android:duration="700"

/>

public

float

getInterpolation(float

input)

{

return

input;

}

public

float

getInterpolation(float

input)

{

return

(float)(Math.cos((input

+

1)

*

Math.PI)

/

2.0f)

+

0.5f;

}

1)計算屬性值/upload/information/20200311/46/191991.jpg

核心類:/upload/information/20200311/46/191992.jpgValueAnimator

animation

=

ValueAnimator.ofFloat(0f,

1f);

animation.setDuration(1000);

animation.addUpdateListener(new

AnimatorUpdateListener()

{

@Override

public

void

onAnimationUpdate(ValueAnimator

animation)

{

Log.i("update",

((Float)

animation.getAnimatedValue()).toString());

}

});

animation.setInterpolator(new

CycleInterpolator(3));

animation.start();

ObjectAnimator

animX

=

ObjectAnimator.ofFloat(myView,

"x",

50f);

ObjectAnimator

animY

=

ObjectAnimator.ofFloat(myView,

"y",

100f);

AnimatorSet

animSetXY

=

new

AnimatorSet();

animSetXY.playTogether(animX,

animY);

animSetXY.start();ropertyValuesHolder

pvhX

=

PropertyValuesHolder.ofFloat("x",

50f);

PropertyValuesHolder

pvhY

=

PropertyValuesHolder.ofFloat("y",

100f);

ObjectAnimator.ofPropertyValuesHolder(myView,

pvhX,

pvyY).start();myView.animate().x(50f).y(100f);//myView.animate()直接返回一個ViewPropertyAnimator對象Keyframe

kf0

=

Keyframe.ofFloat(0f,

0f);

Keyframe

kf1

=

Keyframe.ofFloat(.5f,

360f);

Keyframe

kf2

=

Keyframe.ofFloat(1f,

0f);

PropertyValuesHolder

pvhRotation

=

PropertyValuesHolder.ofKeyframe("rotation",

kf0,

kf1,

kf2);//動畫屬性名,可變參數(shù)

ObjectAnimator

rotationAnim

=

ObjectAnimator.ofPropertyValuesHolder(target,

pvhRotation)

rotationAnim.setDuration(5000);public

static

KeyframeSet

ofFloat(float...

values)

{

int

numKeyframes

=

values.length;

FloatKeyframe

keyframes[]

=

new

FloatKeyframe[Math.max(numKeyframes,2)];

if

(numKeyframes

==

1)

{

keyframes[0]

=

(FloatKeyframe)

Keyframe.ofFloat(0f);

keyframes[1]

=

(FloatKeyframe)

Keyframe.ofFloat(1f,

values[0]);

}

else

{

keyframes[0]

=

(FloatKeyframe)

Keyframe.ofFloat(0f,

values[0]);

for

(int

i

=

1;

i

<

numKeyframes;

++i)

{

keyframes[i]

=

(FloatKeyframe)

Keyframe.ofFloat((float)

i

/

(numKeyframes

-

1),

values[i]);//這里是關鍵

}

}

return

new

FloatKeyframeSet(keyframes);<set

android:ordering="sequentially">

<set>

<objectAnimator

android:propertyName="x"

android:duration="500"

android:valueTo="400"

android:valueType="intType"/>

<objectAnimator

android:propertyName="y"

android:duration="500"

android:valueTo="300"

android:valueType="intType"/>

</set>

<objectAnimator

android:propertyName="alpha"

android:duration="500"

android:valueTo="1f"/>

</set>AnimatorSet

set

=

(AnimatorSet)

AnimatorInflater.loadAnimator(myContext,

R.perty_animator);

set.setTarget(myObject);

set.start();<set

android:ordering=["together"

|

"sequentially"]>

<objectAnimator

android:propertyName="string"

android:duration="int"

android:valueFrom="float

|

int

|

color"

android:valueTo="float

|

int

|

color"

android:startOffset="int"

android:repeatCount="int"

android:repeatMode=["repeat"

|

"reverse"]

android:valueType=["intType"

|

"floatType"]/>

<animator

android:duration="int"

android:valueFrom="float

|

int

|

color"

android:valueTo="float

|

int

|

color"

android:startOffset="int"

android:repeatCount="int"

android:repeatMode=["repeat"

|

"reverse"]

android:valueType=["intType"

|

"floatType"]/>

<set>

...

</set>

</set><Button

android:id="@+id/btn_1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/btn_1"

android:padding="10px"

android:layout_below="@id/touch_feedback_ripple_textview"

/>

<Button

android:id="@+id/btn_2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/btn_2"

android:layout_below="@id/btn_1"

android:padding="10px"

android:background="?android:attr/selectableItemBackground"/>

<Button

android:id="@+id/btn_3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/btn_3"

android:layout_below="@id/btn_2"

android:padding="10px"

android:background="?android:attr/selectableItemBackgroundBorderless"/>/upload/information/20200311/46/191993.jpg

public

static

Animator

createCircularReveal(View

view,nt

centerX,

int

centerY,

float

startRadius,

float

endRadius)

{

return

new

RevealAnimator(view,

centerX,

centerY,

startRadius,

endRadius);

}final

View

oval

=

this.findViewById(R.id.oval);

oval.setOnClickListener(new

View.OnClickListener()

{

@Override

public

void

onClick(View

v)

{

Animator

animator

=

ViewAnimationUtils.createCircularReveal(

oval,oval.getWidth()/2,oval.getHeight()/2,oval.getWidth(),0);

animator.setInterpolator(new

AccelerateDecelerateInterpolator());

animator.setDuration(2000);

animator.start();

}

});

final

View

rect

=

this.findViewById(R.id.rect);

rect.setOnClickListener(new

View.OnClickListener()

{

@Override

public

void

onClick(View

v)

{

Animator

animator

=

ViewAnimationUtils.createCircularReveal(

rect,0,0,0,(float)

Math.hypot(rect.getWidth(),

rect.getHeight()));

animator.setInterpolator(new

AccelerateInterpolator());

animator.setDuration(2000);

animator.start();

}

});

/upload/information/20200311/46/191994.jpg<?xml

version="1.0"

encoding="utf-8"?>

<fade

xmlns:android="/apk/res/"

android:duration="1000"/>

res/transition/activity_slide.xml

<?xml

version="1.0"

encoding="utf-8"?>

<slide

xmlns:android="/apk/res/"

android:duration="1000"/>

@Override

protected

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_transition);

setupWindowAnimations();

}

private

void

setupWindowAnimations()

{

Slide

slide

=

TransitionInflater.from(this).inflateTransition(R.transition.activity_slide);

getWindow().setExitTransition(slide);

}

@Override

protected

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_transition);

setupWindowAnimations();

}

private

void

setupWindowAnimations()

{

Fade

fade

=

TransitionInflater.from(this).inflateTransition(R.transition.activity_fade);

getWindow().setEnterTransition(fade);

}

@Override

protected

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_transition);

setupWindowAnimations();

}

private

void

setupWindowAnimations()

{

Slide

slide

=

new

Slide();

slide.setDuration(1000);

getWindow().setExitTransition(slide);

}

@Override

protected

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_transition);

setupWindowAnimations();

}

private

void

setupWindowAnimations()

{

Fade

fade

=

new

Fade();

fade.setDuration(1000);

getWindow().setEnterTransition(fade);

}

<resources>

<style

name="AppTheme"

parent="Theme.AppCompat.Light.DarkActionBar">

<item

name="colorPrimary">@color/colorPrimary</item>

<item

name="colorPrimaryDark">@color/colorPrimaryDark</item>

<item

name="colorAccent">@color/colorAccent</item>

<!--設置選中的顏色-->

<!--

允許使用transitions

-->

<item

name="android:windowContentTransitions">true</item>

<!--是否覆蓋執(zhí)行,其實可以理解成是否同步執(zhí)行還是順序執(zhí)行-->

<item

name="android:windowAllowEnterTransitionOverlap">false</item>

<item

name="android:windowAllowReturnTransitionOverlap">false</item>

</style>

</resources>

@Override

public

void

onClick(View

v)

{

ArrayList<Pair<View,String>>

arrayList

=

new

ArrayList<Pair<View,String>>();

switch

(v.getId())

{

case

R.id.explode_btn:

setExplodeTransition();

flag

=

AnimConstant.EXPLODE_FLAG;

break;

case

R.id.slide_btn:

setSlideTransition();

flag

=

AnimConstant.SLIDE_FLAG;

break;

case

R.id.pade_in_out_btn:

setFadeTransition();

flag

=

AnimConstant.PADE_IN_OUT_FLAG;

break;

case

R.id.shared_element_btn:

arrayList.add(new

Pair<View,

String>(shareElementBtn,

"shared_name_btn"));

flag

=

AnimConstant.SHARED_ELEMENTS_FLAG;

break;

}

startActivity(arrayList);

}

private

void

setFadeTransition()

{

Fade

fadeTransition

=

new

Fade();

fadeTransition.setDuration(1000);

getWindow().setReenterTransition(fadeTransition);

getWindow().setExitTransition(fadeTransition);

}

private

void

startActivity(ArrayList<Pair<View,

String>>

arrayList)

{

Intent

intent

=

new

Intent();

intent.setClass(this

,SecondActivity.class);

intent.putExtra("transition_flag",flag);

ActivityOptionsCompat

options

=

ActivityOptionsCompat.makeSceneTransitionAnimation(this,

arrayList.toArray(new

Pair[arrayList.size()]));

startActivity(intent,

options.toBundle());

}

private

void

setExplodeTransition()

{

Explode

explode

=

new

Explode();

explode.setDuration(2000);

getWindow().setReenterTransition(explode);

getWindow().setExitTransition(explode);

}

private

void

setSlideTransition()

{

Slide

slideTransition

=

new

Slide();

slideTransition.setSlideEdge(Gravity.LEFT);

slideTransition.setDuration(1000);

getWindow().setReenterTransition(slideTransition);

getWindow().setExitTransition(slideTransition);

}

private

Button

returnBtn

=

null;

@Override

protected

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_second);

Intent

intent

=

getIntent();

int

flag

=

intent.getIntExtra("transition_flag"

,-1);

if

(flag

!=

AnimConstant.SHARED_ELEMENTS_FLAG)

{

setupWindowAnimations();

}

returnBtn

=

(Button)

this.findViewById(R.id.return_btn);

returnBtn.setOnClickListener(new

View.OnClickListener()

{

@Override

public

void

onClick(View

v)

{

finishAfterTransition();

}

});

}

private

void

setupWindowAnimations()

{

Explode

explode

=

new

Explode();

explode.setDuration(2000);

getWindow().setEnterTransition(explode);

}/upload/information/20200311/46/191995.jpg<pathInterpolator

xmlns:android="/apk/res/android"

android:controlX1="0.4"

android:controlY1="0"

android:controlX2="1"

android:controlY2="1"/>public

class

SCPahtInterpolator

extends

PathInterpolator

{

public

static

final

float

DEFALUT_CONTROL_1_X

=

0.5f;

public

static

final

float

DEFALUT_CONTROL_1_Y

=

0f;

public

static

final

float

DEFALUT_CONTROL_2_X

=

0f;

public

static

final

float

DEFALUT_CONTROL_2_Y

=

1f;

public

SCPahtInterpolator()

{

super(DEFALUT_CONTROL_1_X,

DEFALUT_CONTROL_1_Y,

DEFALUT_CONTROL_2_X,

DEFALUT_CONTROL_2_Y);

}

public

SCPahtInterpolator(Path

path)

{

super(path);

}

public

SCPahtInterpolator(float

controlX,

float

controlY)

{

super(controlX,

controlY);

}

public

SCPahtInterpolator(float

controlX1,

float

controlY1,

float

controlX2,

float

controlY2)

{

super(controlX1,

controlY1,

controlX2,

controlY2);

}

public

SCPahtInterpolator(Context

context,

AttributeSet

attrs)

{

super(context,

attrs);

}

}ObjectAnimator

mAnimator;

mAnimator

=

ObjectAnimator.ofFloat(view,

View.X,

View.Y,

path);

...

mAnimator.start();<!--

animate

the

translationZ

property

of

a

view

when

pressed

-->

<selector

xmlns:android="/apk/res/android">

<item

android:state_pressed="true">

<set>

<objectAnimator

android:propertyName="translationZ"

android:duration="@android:integer/config_shortAnimTime"

android:valueTo="2dp"

android:valueType="floatType"/>

<!--

you

could

have

other

objectAnimator

elements

here

for

"x"

and

"y",

or

other

properties

-->

</set>

</item>

<item

android:state_enabled="true"

android:state_pressed="false"

android:state_focused="true">

<set>

<objectAnimator

android:propertyName="translationZ"

android:duration="100"

android:valueTo="0"

android:valueType="floatType"/>

</set>

</item>

</selector><!--

res/drawable/myanimstatedrawable.xml

-->

<animated-selector

xmlns:android="/apk/res/android">

<!--

provide

a

different

drawable

for

each

state-->

<item

android:id="@+id/pressed"

android:drawable="@drawable/drawableP"

android:state_pressed="true"/>

<item

android:id="@+id/focused"

android:drawable="@drawable/drawableF"

android:state_focused="true"/>

<item

android:id="@id/default"

android:drawable="@drawable/drawableD"/>

<!--

specify

a

transition

-->

<tra

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論