百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

ParallaxPager

> 编程语言
开源

为您的 Android 翻页添加一些深度。

770 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

为您的 Android 翻页添加一些深度。

Parallax Pager

Add some depth to your Android scrolling using the parallax effect!

Installation

Step 1. Add the JitPack repository to your build file

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

Step 2. Add the dependency

dependencies {
  implementation 'com.github.prolificinteractive:parallaxpager:${parallaxpagerVersion}'
}

Usage

There are 4 important steps:

  1. Use a ParallaxContainer in layout XML

  2. Create a layout XML file for each page

  3. Wrap the Activity Context

  4. Add the attachment code to onCreate of your Activity or onCreateView of your Fragment

1. Use a ParallaxContainer in layout XML

Use the class com.prolificinteractive.parallaxpager.ParallaxContainer in your layout XML, sizing it however you like.

Ex:

2. Create a layout XML file for each page

Each page must have its own layout XML file. Use whichever Layouts or Views you like, as usual.

Ensure this line is added to the Root Element:

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

Assign any combination of the following attributes (all floats):

  • x_in: as the View enters the screen, it will translate in the horizontal direction along with user swiping, at a rate multiplied by this value. Default is 0.

  • x_out: as the View leaves the screen, it will translate in the horizontal direction along with user swiping, at a rate multiplied by this value. Default is 0.

  • y_in: as the View enters the screen, it will translate downward as the user swipes right to left, at a rate multiplied by this value. Default is 0.

  • y_out: as the View leaves the screen, it will translate upward as the user swipes right to left, at a rate multiplied by this value. Default is 0.

  • a_in: as the View enters the screen, it will fade in as the user swipes right to left, at a rate multiplied by this value. Default is 0.

  • a_out: as the View leaves the screen, it will fade out as the user swipes right to left, at a rate multiplied by this value. Default is 0.

Ex:


  

  

Keep in mind that negative values mean a change in direction for translation effects, and have no effect for alpha. For translation effects, values between 0 and 1 will result in a high level of funkiness.

3. Wrap the Activity Context

Wrap the activity context using com.prolificinteractive.parallaxpager.ParallaxContextWrapper in your activity.

Ex:

  @Override
  protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(new ParallaxContextWrapper(newBase));
  }

Note: If you are using this in conjunction with another library that wraps Context, it doesn't appear to like chaining them together. Instead, we've added the ability to hook into the View creation process to use with other libraries. The sample project shows how to hook into Calligraphy.

Ex:

  @Override
  protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(
        new ParallaxContextWrapper(newBase, new OnViewCreatedListener() {
          @Override public View onViewCreated(View view, Context context, AttributeSet attrs) {
            //Setup view as needed
            return view; //Return the view passed in
          }
        })
    );
  }

4. Add the attachment code to onCreate of your Activity or onCreateView of your Fragment

Important steps in onCreate of an Activity (or onCreateView of a Fragment):

  • Find the parallax container by ID

  • Specify whether the pager should loop (true means it will loop)

  • Submit a Layout Inflater and list the layouts for each page (in order). Currently there must be at least 2 in this list (repeats allowed).

Ex:

// find the parallax container
ParallaxContainer parallaxContainer = (ParallaxContainer) findViewById(R.id.parallax_container);

// specify whether pager will loop
parallaxContainer.setLooping(true);

// wrap the inflater and inflate children with custom attributes
parallaxContainer.setupChildren(getLayoutInflater(),
    R.layout.parallax_view_1,
    R.layout.parallax_view_2,
    R.layout.parallax_view_3,
    R.layout.parallax_view_4);

Extras

Extra 1. Setting a ViewPager.OnPageChangeListener

You can set a ViewPager.OnPageChangeListener after the attachment code in step 4.

// optionally set a ViewPager.OnPageChangeListener
parallaxContainer.setOnPageChangeListener(this);

Extra 2. ViewPager access

You have access to the ViewPager by calling:

parallaxContainer.getViewPager();

This is exposed for use with existing code which requires a ViewPager instance. Please make sure that if you call methods like setAdapter or setOnPageChangeListener on the instance returned, that you do so with forethought and good reason.

Extra 3. Overriding parallax visibility

Parallax views will be VISIBLE when onscreen, and GONE when offscreen. If you need to override this behavior, set this attribute on your View in XML:

app:override_visibility="true"

Contributing

To report a bug or enhancement request, feel free to file an issue under the respective heading. If you wish to contribute to the project, fork this repo and submit a pull request.

Code contributions should follow the standards specified in the Prolific Android Code Style.

License

Copyright (c) 2018 Prolific Interactive

Parallax Pager is maintained and sponsored by Prolific Interactive. It may be redistributed under the terms specified in the LICENSE file.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言