Android实现循环平移动画示例
实现用一张背景图做循环从左往右平移动画。
1、实现两个animationxml文件,一个起始位置在-100%p,一个在0%p。设置repeat属性为循环,重复。
<?xmlversion="1.0"encoding="utf-8"?>
<setxmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator">
<translateandroid:fromXDelta="0%p"android:toXDelta="100%p"
android:repeatMode="restart"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:duration="30000"/>
</set>
<?xmlversion="1.0"encoding="utf-8"?>
<setxmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator">
<translateandroid: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的动画分别对应上面那两个animation。
<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"/>
Animationanim=AnimationUtils.loadAnimation(mContext,R.anim.home_animation); ImageViewanimationTopRightView=(ImageView)this.findViewById(R.id.animation_top_right); animationTopRightView.startAnimation(anim);
Animationanim2=AnimationUtils.loadAnimation(mContext,R.anim.home_animation2); ImageViewanimationTopLeftView=(ImageView)this.findViewById(R.id.animation_top_left); animationTopLeftView.startAnimation(anim2);
热门推荐
10 三八简短祝福语给婆婆
11 相恋人回去祝福语简短
12 生日祝福语贺卡文字简短
13 学院祝福语女生大全简短
14 婶婶生日贺词简短祝福语
15 公司开年仪式祝福语简短
16 父亲祝福语大全简短语
17 女儿结婚账单祝福语简短
18 送去考试祝福语大全简短