淺談Android中視圖動畫的屬性與使用
簡介
Android動畫主要包括視圖動畫和屬性動畫,視圖動畫包括Tween動畫和Frame動畫,Tween動畫又包括漸變動畫、平移動畫、縮放動畫、旋轉(zhuǎn)動畫。
Tween動畫的基本屬性
目標(biāo) View;
時常 duration;
開始狀態(tài) fromXXX;
結(jié)束動畫 toXXX;
開始時間 startOffset;
重復(fù)次數(shù) repeatCount;
時間軸 interpolator(插值器)。
代碼示例
xml實(shí)現(xiàn)
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="100%" android:toYDelta="0" android:fillAfter="true" android:duration="3000"> </translate>
在代碼中調(diào)用
Animation translate = AnimationUtils.loadAnimation(context,R.anim.translate); imageView.startAnimation(translate);
補(bǔ)充:
1.對于縮放和旋轉(zhuǎn)動畫,有一個pivotX或者pivotY,表示的是縮放或旋轉(zhuǎn)的中心點(diǎn)。
對應(yīng)的屬性值有三種寫法。
· 數(shù)值 50 表示當(dāng)前控件的左上角加上50px;
· 百分?jǐn)?shù) 50% 表示當(dāng)前控件的50%;
· 百分?jǐn)?shù)p 50%p 表示父控件的50%。
2.在一個動畫集合里,可以通過設(shè)置stratOffset屬性,來實(shí)現(xiàn)多個動畫并行和串行的效果。
Frame動畫
Frame動畫的配置文件放在drawable目錄下
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image1" android:duration="50"/> <item android:drawable="@drawable/image2" android:duration="50"/> <item android:drawable="@drawable/image3" android:duration="50"/> </animation-list>
// 需要先設(shè)置成背景 imageView.setBackgroundResource(R.drawable.frame_anim); AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); frameAnimation.start();
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容能對大家開發(fā)Android的時候有所幫助,如果有疑問大家可以留言交流。
相關(guān)文章
android: targetSdkVersion升級中Only fullscreen activities can r
這篇文章主要給大家介紹了關(guān)于Android target SDK和build tool版本升級中遇到Only fullscreen activities can request orientation問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-09-09
Android編程實(shí)現(xiàn)ViewPager多頁面滑動切換及動畫效果的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)ViewPager多頁面滑動切換及動畫效果的方法,以完整實(shí)例形式分析了ViewPager多頁面滑動切換效果的布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11
Android實(shí)現(xiàn)注冊登錄界面的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)注冊登錄界面的實(shí)例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05
Android webview 遇到android.os.FileUriExposedException錯誤解決辦法
這篇文章主要介紹了Android webview 遇到android.os.FileUriExposedException錯誤解決辦法的相關(guān)資料,希望通過本文能幫助到大家,讓大家遇到這樣的問題解決,需要的朋友可以參考下2017-10-10
在Android中使用SQLite數(shù)據(jù)庫及其操作詳解
在?Android?開發(fā)中,使用?SQLite?數(shù)據(jù)庫是一種常見的持久化數(shù)據(jù)存儲方式,本文將通過代碼示例詳細(xì)講解如何在?Android?中創(chuàng)建數(shù)據(jù)庫表、插入數(shù)據(jù)、執(zhí)行查詢操作以及驗(yàn)證查詢結(jié)果,需要的朋友可以參考下2024-08-08
Android自定義Dialog實(shí)現(xiàn)通用圓角對話框
這篇文章主要為大家詳細(xì)介紹了Android自定義Dialog實(shí)現(xiàn)通用圓角對話框,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-11-11
Android自定義頂部導(dǎo)航欄控件實(shí)例代碼
這篇文章主要介紹了Android自定義頂部導(dǎo)航欄控件實(shí)例代碼,需要的朋友可以參考下2017-12-12
Android組件TabHost實(shí)現(xiàn)頁面中多個選項(xiàng)卡切換效果
這篇文章主要為大家詳細(xì)介紹了Android組件TabHost實(shí)現(xiàn)頁面中多個選項(xiàng)卡切換效果的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-05-05
Android添加指紋解鎖功能的實(shí)現(xiàn)代碼
當(dāng)開發(fā)的APP需要加密驗(yàn)證時可以考慮添加系統(tǒng)指紋解鎖功能。這篇文章主要介紹了Android添加指紋解鎖功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-07-07

