Android Loop panning Animation

Source: Internet
Author: User


The implementation uses a background image to do a loop shift animation from left to right.

1. Implement two animation XML files, one starting position in -100%p, and one in 0%p. Set the Repeat property to loop, repeating.


<?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. In the layout of the view, you put two identical view backgrounds, and the view animation corresponds to the above two 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 Loop panning Animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.