Android實現(xiàn)循環(huán)平移動畫示例
更新時間:2015年06月09日 11:31:07 投稿:junjie
這篇文章主要介紹了Android實現(xiàn)循環(huán)平移動畫示例,本文講解實現(xiàn)用一張背景圖做循環(huán)從左往右平移動畫,需要的朋友可以參考下
實現(xiàn)用一張背景圖做循環(huán)從左往右平移動畫。
1、實現(xiàn)兩個animation xml文件,一個起始位置在-100%p ,一個在0%p。設(shè)置repeat屬性為循環(huán),重復(fù)。
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="0%p" android:toXDelta="100%p"
android:repeatMode="restart"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:duration="30000" />
</set>
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-100%p" android:toXDelta="0%p"
android:repeatMode="restart"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:duration="30000" />
</set>
2、在view的layout里面放兩個一樣的view做背景,view的動畫分別對應(yīng)上面那兩個animation。
復(fù)制代碼 代碼如下:
<ImageView
android:id="@+id/animation_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
android:src="@drawable/home_animation_bg" />
<ImageView
android:id="@+id/animation_top_right" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
android:src="@drawable/home_animation_bg" />
復(fù)制代碼 代碼如下:
Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.home_animation);
ImageView animationTopRightView = (ImageView)this.findViewById(R.id.animation_top_right);
animationTopRightView.startAnimation(anim);
復(fù)制代碼 代碼如下:
Animation anim2 = AnimationUtils.loadAnimation(mContext, R.anim.home_animation2);
ImageView animationTopLeftView = (ImageView)this.findViewById(R.id.animation_top_left);
animationTopLeftView.startAnimation(anim2);
相關(guān)文章
Android仿QQ復(fù)制昵稱效果的實現(xiàn)方法
這篇文章主要介紹了Android仿QQ復(fù)制昵稱效果的實現(xiàn)方法,主要依賴的是一個開源項目,需要的朋友可以參考下2019-05-05Android實現(xiàn)設(shè)置APP灰白模式效果
大家好,本篇文章主要講的是Android實現(xiàn)設(shè)置APP灰白模式效果,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12kotlin中數(shù)據(jù)類重寫setter getter的正確方法
這篇文章主要給大家介紹了關(guān)于kotlin中數(shù)據(jù)類重寫setter getter的正確方法,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用kotlin具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06