Skip to content
Related Articles

Related Articles

Scroll ImageView in Android

Improve Article
Save Article
  • Last Updated : 11 Jun, 2021
Improve Article
Save Article

In this article, we are going to implement a very important feature related to the ImageView. The image will keep on scrolling horizontally by itself. When we click on the image then it will stop scrolling and when we again click it will again keep scrolling. We can use this feature to show animation in an app. This feature can be used in Online Shopping App. When the item is out for delivery then they can use this feature to show destination. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Scroll ImageView in Android Sample GIF

Step By Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency and JitPack Repository

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

implementation ‘com.github.Q42:AndroidScrollingImageView:1.3.4’

Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.

allprojects {

 repositories {


   maven { url “” }



After adding this dependency sync your project and now we will move towards its implementation.  

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. There are three attributes for the Scrolling ImageView:

  • speed is the number of dp to move the drawable per second
  • source is drawable to paint. May refer to an array of drawable
  • contiguous When the source is an array of drawable, contiguous determine their ordering.


<?xml version="1.0" encoding="utf-8"?>
            scrolling_image_view:speed="60dp" />
            scrolling_image_view:speed="150dp" />
        android:src="@drawable/van" />

Note: Drawable Files can be found here.

Step 4: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    boolean moving1 = true, moving2 = true;
    protected void onCreate(Bundle savedInstanceState) {
        final ScrollingImageView scrollingBackground = (ScrollingImageView) findViewById(;


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!