Giter VIP home page Giter VIP logo

parallaxviewpager's Introduction

ParallaxViewPager

License

δΈ­ζ–‡

The first gif
foreground speed = 2*background speed witch is speedRatio = 0.5
the second gif
foreground speed = background speed witch is speedRatio = 1

Add to your project

Gradle

  • Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
    	...
    	maven { url 'https://jitpack.io' }
    }
}
  • Add the dependency
dependencies {
    compile 'com.github.demoNo:ParallaxViewPager:v1.0.0'
}

Maven

  • Add the JitPack repository to your build file
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
  • Add the dependency
<dependency>
    <groupId>com.github.demoNo</groupId>
    <artifactId>ParallaxViewPager</artifactId>
    <version>v1.0.0</version>
</dependency>

Usage

  • Just like normal ViewPager
<li.yohan.parallax.ParallaxViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
ParallaxViewPager mPager = ((ParallaxViewPager) findViewById(R.id.pager));
mPager.setAdapter(new Adapter());

set background image just like ViewPager.

you can set in xml

android:background="@drawable/background"

or in code

setBackgroundResource(int resid)
setBackground(Drawable background)

Configuration

  • you can set speed ratio in xml
 <li.yohan.parallax.ParallaxViewPager
     android:id="@+id/viewPager"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    app:speedRatio="0.5f" />
  • also set in code
 ParallaxViewPager mPager = ((ParallaxViewPager) findViewById(R.id.pager));
 mPager.setAdapter(new Adapter());
+mPager.setSpeedRatio(0.5f);

Note: the default ratio is 0.5f

Restrictions

  1. The background image's width should larger than height.
  2. The background image's width should larger than ViewPager's width.
  3. You can't set pager with padding.
  4. If the ratio that user set is not proper, it will be recalculate and reset.

Licence

Apache License, Version 2.0

parallaxviewpager's People

Contributors

demono avatar

Watchers

 avatar  avatar  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.