Giter Club home page Giter Club logo

androidscrollingimageview's Introduction

Scrolling Image View

An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Example

Example

Installation

Step 1. Add the JitPack repository to your project build.gradle file

allprojects {
    repositories {
        // ~~~
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency in the form

dependencies {
    implementation 'com.github.Q42:AndroidScrollingImageView:1.3.4'
}

Sample app

Please see the sample app for some examples

Sample App

Usage

In your Android layout file add:

<com.q42.android.scrollingimageview.ScrollingImageView
    android:id="@+id/scrolling_background"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    scrolling_image_view:speed="60dp"
    scrolling_image_view:contiguous="false"
    scrolling_image_view:source="@drawable/scrolling_background" />

There are three attributes for the ScrollingImageView:

  • speed is the number of dp's to move the drawable per second (may be a negative number)

  • source is the drawable to paint. May refer to an array of drawables

  • contiguous When source is an array of drawables, contiguous determines their ordering.

    false (default) for random ordering, true for the same order as in the array

Don't forget to add the namespace to your root XML element

xmlns:scrolling_image_view="http://schemas.android.com/apk/res-auto"

In your Java code, you can start and stop the animation like this:

ScrollingImageView scrollingBackground = (ScrollingImageView) loader.findViewById(R.id.scrolling_background);
scrollingBackground.stop();
scrollingBackground.start();

Parallax effect

In order to achieve a parallax effect, you can stack multiple ScrollingImageView's in a FrameLayout with different speeds. For example:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  <com.q42.android.scrollingimageview.ScrollingImageView
      android:id="@+id/scrolling_background"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      scrolling_image_view:speed="60dp"
      scrolling_image_view:source="@drawable/scrolling_background" />
      
  <com.q42.android.scrollingimageview.ScrollingImageView
      android:id="@+id/scrolling_foreground"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      scrolling_image_view:speed="150dp"
      scrolling_image_view:source="@drawable/scrolling_foreground" />
</FrameLayout>

androidscrollingimageview's People

Contributors

tsuijten avatar ninovanhooff avatar long1eu avatar gerpanobanano avatar shaunidiot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.