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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Creating Apps With Material Design —— Defining Custom Animations

發布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Creating Apps With Material Design —— Defining Custom Animations 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載請注明?http://blog.csdn.net/eclipsexys?翻譯自Developer Android,時間倉促,有翻譯問題請留言指出。謝謝


定義動畫

在材料設計動畫讓用戶與您的應用程序進行交互時,為他們的行為提供反饋。并提供可視化的連續性。

該材料的主題提供了一些默認的動畫button和活動過渡,而Android5.0(API等級21)以上,您能夠自己定義這些動畫和創建新的:?


? ? 觸摸反饋?
? ? 通告顯示?
? ? 活動轉變?
? ? 曲線運動?
? ? 視圖狀態更改?

自己定義觸摸反饋?


觸摸反饋在材料設計提供了一種瞬時視覺確認在接觸點上,當用戶與用戶界面元素進行交互。默認的觸摸反饋的動畫button,使用新的RippleDrawable類來實現不同狀態之間的轉換與產生連鎖反應動畫。

?

在大多數情況下,你應該通過指定視圖背景。在視圖中的XML應用此功能:


    ?android:attr/selectableItemBackground for a bounded ripple?

android:attr/selectableItemBackgroundBorderless for a ripple that extends beyond the view


或者,你能夠定義一個RippleDrawable為使用波紋元素的XML資源。?

您能夠指定一種顏色RippleDrawable對象。要更改默認的觸摸反饋的顏色,使用的主題的android:colorControlHighlight屬性。


使用Reveal Effect


Reveal動畫為用戶提供視覺的連續性,當您顯示或隱藏一組UI元素。該ViewAnimationUtils.createCircularReveal()方法。您能夠設置動畫clipping circle來顯示或隱藏視圖。

?

要使用此效果顯示先前不可見的view:

// previously invisible view
View myView = findViewById(R.id.my_view);// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;// get the final radius for the clipping circle
int finalRadius = myView.getWidth();// create and start the animator for this view
// (the start radius is zero)
Animator anim =ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
anim.start();

要使用此效果隱藏先前看到的view:

// previously visible view
final View myView = findViewById(R.id.my_view);// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;// get the initial radius for the clipping circle
int initialRadius = myView.getWidth();// create the animation (the final radius is zero)
Animator anim =ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {@Overridepublic void onAnimationEnd(Animator animation) {super.onAnimationEnd(animation);myView.setVisibility(View.INVISIBLE);}
});// start the animation
anim.start();


自己定義Activity transitions


在材料設計應用程序的Activity通過運動來進行不同狀態之間的轉換。

您能夠指定自己定義動畫的進入和退出的過渡和Activity之間共享內容的轉換。?

Android5.0(API級別21)支持這些進入和退出的轉換:?

? ? 爆炸 - 從現場的中心移動的view。?
? ? 幻燈片 - 移動視圖或從場景的邊緣。?
? ? 褪色 - 通過改變其透明度加入或刪除場景視圖。?

transition擴展了能見度類的不論什么變化都支持作為進入或退出轉型。欲了解很多其它信息,請參閱該轉換類的API參考。?

Android5.0(API級別21)也支持這些共同的元素轉換:?

? ? changeBounds - 動畫處理目標View布局界限。

?
? ? changeClipBounds - 動畫處理目標View區域剪輯。

?
? ? changeTransform - 動畫處理目標View縮放和旋轉。?
? ? changeImageTransform - 動畫處理改變目標圖像的大小和比例。?

當您在應用程啟用Activity轉變時,默認以交叉漸變過渡的進入和退出Activity的啟動。



指定自己定義的轉換?


首先。當你定義一個風格,繼承了材料的主題屬性使窗體內容轉換 Android:windowContentTransitions。您也能夠指定進入。退出,并指定您定義的樣式共享元素的轉換:

<style name="BaseAppTheme" parent="android:Theme.Material"><!-- enable window content transitions --><item name="android:windowContentTransitions">true</item><!-- specify enter and exit transitions --><item name="android:windowEnterTransition">@transition/explode</item><item name="android:windowExitTransition">@transition/explode</item><!-- specify shared element transitions --><item name="android:windowSharedElementEnterTransition">@transition/change_image_transform</item><item name="android:windowSharedElementExitTransition">@transition/change_image_transform</item>
</style>

在這個樣例中。change_image_transform過渡的定義例如以下:

<!-- res/transition/change_image_transform.xml -->
<!-- (see also Shared Transitions below) -->
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"><changeImageTransform/>
</transitionSet>

該changeImageTransform元素相應于ChangeImageTransform類。欲了解很多其它信息,請參閱轉換的API參考。?

為確保窗體移動動畫實現,須要調用Window.requestFeature()方法:

// inside your activity (if you did not enable transitions in your theme)
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);// set an exit transition
getWindow().setExitTransition(new Explode());

要指定你的代碼轉換,調用這些方法與Transition對象:?

? ? Window.setEnterTransition()?
? ? Window.setExitTransition()?
? ? Window.setSharedElementEnterTransition()?
? ? Window.setSharedElementExitTransition()?

該setExitTransition()和setSharedElementExitTransition()方法定義為調用活動的退出過渡。

該setEnterTransition()和setSharedElementEnterTransition()方法定義了稱為活動的輸入過渡。

?

為了得到一個過渡的完整效果。您必須啟用這兩個主叫和被叫的活動窗體中的內容轉換。否則。調用活動將啟動退出過渡,但隨后你會看到一個窗體的過渡(如規?;蛲噬?#xff09;。?

開始盡快的進入過渡,使用Window.setAllowEnterTransitionOverlap()方法被調用的Activity。這讓你有很多其它戲劇性的進入過渡動畫。?


使用轉換開始活動?


假設啟用轉換并設置為Activity的退出過渡,當您啟動還有一個Activity時。例如以下的轉變被激活:

startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

假設您設置了進入轉型的第二個活動,過渡也是該活動開始時激活。

要禁用轉換,當你開始還有一項活動,提供了一個null的選項。

?

實現一個共同的元素之間的屏幕過渡動畫


? ? 讓你的主題窗體的內容轉換。?
? ? 指定你的風格的共享元素的過渡。?
? ? 定義轉換為XML資源。?
? ? 指定一個共同的名字在兩個布局與Android的共享元素:transitionName屬性。

?
? ? 使用ActivityOptions.makeSceneTransitionAnimation()方法。

// get the element that receives the click event
final View imgContainerView = findViewById(R.id.img_container);// get the common element for the transition in this activity
final View androidRobotView = findViewById(R.id.image_small);// define a click listener
imgContainerView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent = new Intent(this, Activity2.class);// create the transition animation - the images in the layouts// of both activities are defined with android:transitionName="robot"ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, androidRobotView, "robot");// start the new activitystartActivity(intent, options.toBundle());}
});

對于您的代碼生成共享動態視圖。使用View.setTransitionName()方法在兩個Activity中指定一個共同的元素名稱。?

為了扭轉場景過渡動畫,當你完畢了第二個活動,叫Activity.finishAfterTransition()方法。而不是Activity.finish()。?


啟動有多個共享的元素的Activity?


為了使兩項活動有多個共享的元素,定義了兩種布局方式與Android的共享元素之間的場景過渡動畫:transitionName屬性(或使用View.setTransitionName()在這兩個活動的方法),并創建一個ActivityOptions對象例如以下:

ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,Pair.create(view1, "agreedName1"),Pair.create(view2, "agreedName2"));

使用Curves Motion

在材料設計的動畫依賴于曲線插補時間和空間上的運動模式。

採用Android5.0(API等級21)以上,則能夠定義自己定義定時曲線和曲線運動模式的動畫。?

該PathInterpolator類是基于貝塞爾曲線或路徑對象上的新插值。該插補指定一個1x1正方形的運動曲線。用(0,0)定位點和(1,1)和控制點使用構造函數的參數指定。

您也能夠定義一個路徑插補為XML資源:

<pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"android:controlX1="0.4"android:controlY1="0"android:controlX2="1"android:controlY2="1"/>

該系統提供的XML資源中的材料設計規范的三個基本曲線:?

    @interpolator/fast_out_linear_in.xml@interpolator/fast_out_slow_in.xml@interpolator/linear_out_slow_in.xml


你能夠通過一個PathInterpolator對象的Animator.setInterpolator()方法。

?

該ObjectAnimator類有新的構造函數。使您能夠同一時候使用兩種或兩種以上的屬性,在一次路徑動畫坐標。比如,以下的動畫師使用Path對象進行動畫視圖的x和y屬性:

ObjectAnimator mAnimator;
mAnimator = ObjectAnimator.ofFloat(view, View.X, View.Y, path);
...
mAnimator.start();

視圖動畫狀態改變


該StateListAnimator類能夠定義動畫執行時的視圖狀態發生改變。

以下的演示樣例演示怎樣為XML資源定義一個StateListAnimator:

<!-- animate the translationZ property of a view when pressed -->
<selector xmlns:android="http://schemas.android.com/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 elementshere 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>

要高度自己定義的視圖狀態動畫視圖,定義使用XML資源文件里選擇元素在這個樣例中的動畫,并將其分配給您的視圖與Android:stateListAnimator屬性。在代碼分配一個狀態表動畫到一個視圖中,使用AnimationInflater.loadStateListAnimator()方法,以及動畫分配給你的View與View.setStateListAnimator()方法。?

當你的主題擴展了材料的主題,button都為Z動畫默認。為了避免你的button此問題,設置了android:stateListAnimator屬性來@null。

?

該AnimatedStateListDrawable類用于創建,顯示相關的視圖狀態更改的動畫可繪。

默認情況下,一些安卓5.0系統部件的使用這些動畫。以下的演示樣例演示怎樣為XML資源定義一個AnimatedStateListDrawable:

<!-- res/drawable/myanimstatedrawable.xml -->
<animated-selectorxmlns:android="http://schemas.android.com/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 --><transition android:fromId="@+id/default" android:toId="@+id/pressed"><animation-list><item android:duration="15" android:drawable="@drawable/dt1"/><item android:duration="15" android:drawable="@drawable/dt2"/>...</animation-list></transition>...
</animated-selector>


Animate?Vector Drawables


矢量可繪制具有可擴展性又不失清晰。該AnimatedVectorDrawable類,您能夠設置動畫的矢量繪制的屬性。

?

你通常在三個XML文件里定義動畫矢量可繪制對象:?

    A vector drawable with the <vector> element in res/drawable/An animated vector drawable with the <animated-vector> element in res/drawable/One or more object animators with the <objectAnimator> element in res/anim/


矢量動畫可繪制對象能夠動畫的<group>的屬性和<path>元素。 <group>元素定義了一組路徑或小組,并在<path>元素定義要繪制的路徑。

?

當你定義你想要的動畫矢量繪制,使用android:name屬性為唯一的名稱分配給組和路徑。這樣你就能夠把它們從你的動畫定義。比如:

<!-- res/drawable/vectordrawable.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"android:height="64dp"android:width="64dp"android:viewportHeight="600"android:viewportWidth="600"><groupandroid:name="rotationGroup"android:pivotX="300.0"android:pivotY="300.0"android:rotation="45.0" ><pathandroid:name="v"android:fillColor="#000000"android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" /></group>
</vector>

動畫繪制矢量的定義是指通過他們的名字矢量繪制的組和路徑:

<!-- res/drawable/animvectordrawable.xml -->
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"android:drawable="@drawable/vectordrawable" ><targetandroid:name="rotationGroup"android:animation="@anim/rotation" /><targetandroid:name="v"android:animation="@anim/path_morph" />
</animated-vector>

動畫的定義代表ObjectAnimator或AnimatorSet對象。在這個樣例中,第一動畫旋轉目標組360度:

<!-- res/anim/rotation.xml -->
<objectAnimatorandroid:duration="6000"android:propertyName="rotation"android:valueFrom="0"android:valueTo="360" />

在本實施例中的第二動畫搖身一變載體可拉伸的路徑從一個形狀到還有一種。

兩個路徑必須是變形兼容:它們必須具有同樣數目的命令和每一個命令的參數的數量同樣。


<!-- res/anim/path_morph.xml -->
<set xmlns:android="http://schemas.android.com/apk/res/android"><objectAnimatorandroid:duration="3000"android:propertyName="pathData"android:valueFrom="M300,70 l 0,-70 70,70 0,0   -70,70z"android:valueTo="M300,70 l 0,-70 70,0  0,140 -70,0 z"android:valueType="pathType" />
</set>

ps:path畫畫,編寫更復雜的路徑,需要使用SVG編輯

轉載于:https://www.cnblogs.com/gcczhongduan/p/4844891.html

總結

以上是生活随笔為你收集整理的Creating Apps With Material Design —— Defining Custom Animations的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 天天黄色片 | 成年人免费看视频 | 男女男精品视频 | 免费无码不卡视频在线观看 | 中文字幕理伦片免费看 | 久久精品波多野结衣 | 婷婷深爱 | 秘密的基地 | 国产精品久久久久久久久晋中 | 国产在线导航 | 国产又黄又猛 | 欧美韩国日本一区 | 亚洲网站av | 国产剧情在线一区 | 影音先锋人妻啪啪av资源网站 | 人体写真 福利视频 | 未满十八岁勿进 | 欧美成人h版在线观看 | 手机在线免费看av | 伊人手机在线视频 | 麻豆md0034在线观看 | 毛片毛片毛片毛片毛片毛片毛片毛片 | 亚洲国产精品狼友在线观看 | 国产一区二区激情视频 | 先锋av资源网站 | 亚洲激情久久 | 东北高大丰满bbbbzbbb | 蜜臀av无码精品人妻色欲 | 偷看洗澡一二三区美女 | 怡红院一区二区三区 | 韩国美女一区 | 国产精品99久久久久 | 欧美中文字幕一区 | 男女av免费 | 国精品无码一区二区三区 | av资源导航 | 俄罗斯毛片基地 | 蜜桃视频欧美 | 美日韩精品 | 国产青草视频在线观看 | 国产福利小视频在线 | 久久色播| 一级α片免费看刺激高潮视频 | 国产精品第7页 | www国产| 久久天堂精品 | 国产成人无码精品久久久性色 | 久久综合九色综合网站 | 久久久国产精品人人片 | 国模私拍av | 国产一区二区三区毛片 | 97超碰网 | 亚洲激情片 | 国产精品sm| 蜜桃麻豆视频 | 日韩中文字幕精品视频 | 牛牛影视一区二区三区 | 男人的亚洲天堂 | 欧美国产中文字幕 | 在线中文字幕一区二区 | 特级西西www444人体聚色 | 色播在线播放 | 日韩欧美国产一区二区三区在线观看 | 欧美图片一区二区 | 国产麻豆电影在线观看 | 成人试看120秒体验区 | 黄色网址在线免费观看 | 一区二区三区免费观看 | 国产成人在线观看免费 | 欧美碰碰碰 | 男女激情视频网站 | 午夜精品一区二 | 99re在线视频 | 福利在线一区二区三区 | 乱图区 | 久久久久久一 | 中文字幕人妻丝袜二区 | 日韩在线不卡一区 | av中文在线资源 | 一区二区三区视频在线观看免费 | 69精品国产 | 日韩性猛交ⅹxxx乱大交 | 欧美激情综合五月色丁香 | 国产精品久久久久久久久免费软件 | 韩国黄色网| 宅男在线视频 | 亚洲成人黄色影院 | 欧美中文字幕在线视频 | 自拍偷拍亚洲欧美 | 成人福利一区 | 日韩中文一区 | 嫩草懂你 | 欧美www视频| 国产一区毛片 | 一区二区日韩精品 | 两性囗交做爰视频 | www.精品视频 | 欧美在线日韩在线 | 成人国产精品免费 |