生活不能沒有運動,so讓我們動起來吧^^~
下面分享幾個簡單撰茎、常用嵌牺、不易出錯的動效。
要點
- 文字滾動龄糊。
- 視圖自帶的動畫逆粹。
- 拋物位移。
- 按壓水面波紋效果炫惩。
- 共享元素動畫枯饿。
Demo
一如既往的霍爾首頁^^:
要點講解
- 文字滾動:
把下面這段代碼放入Layout即可。
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:padding="@dimen/text_margin"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="滾動的 TextView ^ ^
abcdefghijklmnopqrstuvwxyz 1234567890
one two three four five six seven eight nine ten "/>
- 使用View自帶動畫:
下面這段代碼诡必,如果hasShowingAnimation奢方,那么將mSelfAnimationTv復原搔扁,否則將mSelfAnimationTv順時針轉(zhuǎn)90度、透明度漸變?yōu)?.5蟋字、下移300像素稿蹲、放大1.3倍。
boolean hasShowingAnimation;
/*View 自身動畫*/
private void showSelfAnimation() {
if (hasShowingAnimation)
mSelfAnimationTv.animate()
.rotation(0)
.alpha(1f)
.translationY(0)
.scaleX(1f)
.scaleY(1f);
else
mSelfAnimationTv.animate()
.rotation(90)
.alpha(0.5f)
.translationY(300)
.scaleX(1.3f)
.scaleY(1.3f);
hasShowingAnimation = !hasShowingAnimation;
}
- 拋物位移:
請看源碼 - 按壓水面波紋效果:
非常簡單鹊奖,在res-drawable文件夾添加一個bg_btn.xml文件苛聘,代碼如下,然后將其作為Button忠聚、TextView等可點擊控件的背景即可设哗。
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#dfa">
<item>
<selector>
<item
android:drawable="@android:color/transparent"
android:state_pressed="true">
</item>
<item android:drawable="@android:color/white"/>
</selector>
</item>
</ripple>
- 共享元素動畫
查看源碼
要點請看源碼,實現(xiàn)起來很簡單两蟀、很神奇网梢,關鍵是這個方法ActivityOptionsCompat.makeSceneTransitionAnimation()。
使用該Transition需要注意如下幾點:
1.轉(zhuǎn)場兩邊的控件內(nèi)容需一致(比如圖片文字需相同);
2.如果圖片通過網(wǎng)絡加載赂毯,請保證圖片加載庫一致战虏,另外使用Fresco加載圖片會有點問題,這里有解決方案(但是我沒能看懂党涕,所以我又compile了Picasso)烦感。
相關
本文Demo: https://github.com/XunMengWinter/Fly
Material Design初露鋒芒: http://www.reibang.com/p/e64a4e08f57a