Android实现循环平移动画示例

 更新时间:2015年06月09日 11:31:07   投稿:junjie  
这篇文章主要介绍了Android实现循环平移动画示例,本文讲解实现用一张背景图做循环从左往右平移动画,需要的朋友可以参考下

实现用一张背景图做循环从左往右平移动画。

1、实现两个animation xml文件,一个起始位置在-100%p ,一个在0%p。设置repeat属性为循环,重复。

复制代码 代码如下:

<?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>

复制代码 代码如下:

<?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的动画分别对应上面那两个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" />

复制代码 代码如下:

Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.home_animation);
ImageView animationTopRightView = (ImageView)this.findViewById(R.id.animation_top_right);
animationTopRightView.startAnimation(anim);

复制代码 代码如下:

Animation anim2 = AnimationUtils.loadAnimation(mContext, R.anim.home_animation2);
ImageView animationTopLeftView = (ImageView)this.findViewById(R.id.animation_top_left);
animationTopLeftView.startAnimation(anim2);

相关文章

  • Android仿QQ复制昵称效果的实现方法

    Android仿QQ复制昵称效果的实现方法

    这篇文章主要介绍了Android仿QQ复制昵称效果的实现方法,主要依赖的是一个开源项目,需要的朋友可以参考下
    2019-05-05
  • Android小程序实现选项菜单

    Android小程序实现选项菜单

    这篇文章主要为大家详细介绍了Android小程序实现选项菜单,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-05-05
  • Android AsyncTask源码分析

    Android AsyncTask源码分析

    这篇文章主要针对Android AsyncTask源码为大家进行分析,非常方便的AsyncTask类内部封装了Handler和线程池,感兴趣的小伙伴们可以参考一下
    2016-04-04
  • Android处理时间各种方法汇总

    Android处理时间各种方法汇总

    这篇文章主要汇总了Android处理时间的各种方法,如何获取当前时间,日期之间的比较,如何计算两段日期的重合日期等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • Android入门之Gallery用法实例解析

    Android入门之Gallery用法实例解析

    这篇文章主要介绍了Android入门之Gallery用法,对Android初学者有一定的参考学习价值,需要的朋友可以参考下
    2014-08-08
  • Android实现横向二级菜单

    Android实现横向二级菜单

    这篇文章主要为大家详细介绍了Android实现横向二级菜单的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-03-03
  • Android实现设置APP灰白模式效果

    Android实现设置APP灰白模式效果

    大家好,本篇文章主要讲的是Android实现设置APP灰白模式效果,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下,方便下次浏览
    2021-12-12
  • RollViewPager图片轮播效果开源框架使用方法详解

    RollViewPager图片轮播效果开源框架使用方法详解

    这篇文章主要为大家详细介绍了RollViewPager图片轮播效果开源框架的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-10-10
  • kotlin中数据类重写setter getter的正确方法

    kotlin中数据类重写setter getter的正确方法

    这篇文章主要给大家介绍了关于kotlin中数据类重写setter getter的正确方法,文中通过示例代码介绍的非常详细,对大家学习或者使用kotlin具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-06-06
  • OpenGL ES着色器使用详解(二)

    OpenGL ES着色器使用详解(二)

    这篇文章主要为大家详细介绍了OpenGL ES着色器的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05

最新评论