Parallax Layer Layout


Source link: https://github.com/SchibstedSpain/parallax-layer-layout

Parallax Layer Layout

Let's you add layered parallax effect to your Android views or images based on things like device rotation.

We use it at InfoJobs for our error and empty states.



Usage | Download | How it works | Customize | Contribute

Usage

In your layout wrap your layers inside a ParallaxLayerLayout:

<com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout
  android:id="@+id/parallax"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <View

android:id="@+id/layer_3"

android:layout_width="180dp"

android:layout_height="180dp"

android:background="@color/colorPrimaryDark" />
  <View

android:id="@+id/layer_2"

android:layout_width="120dp"

android:layout_height="120dp"

android:background="@color/colorPrimary" />
  <View

android:id="@+id/layer_1"

android:layout_width="80dp"

android:layout_height="80dp"

android:background="@color/colorAccent" />

</com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout>

In your code create a TranslationUpdater and link it with the ParallaxLayerLayout:

sensorTranslationUpdater = new SensorTranslationUpdater(this);
 parallaxLayout.setTranslationUpdater(sensorTranslationUpdater);
  // onResume sensorTranslationUpdater.registerSensorManager();
  // onPause sensorTranslationUpdater.unregisterSensorManager();

Note: Just for the sensor updater you'll need to register and unregister it in your onResume/onPause.

# Download Grab the latest version from jCenter:

dependencies {

compile 'com.schibsted.spain:parallax-layer-layout:1.1.1' 
}

How it works

The layout applies a maximum offset to each of its views, starting with a base offset and adding one offset increment for each layer.

The higher view in the Z index is the closest one from the user perspective so it will only move with the base offset. The further the view from the user, the more it will move.

The parallax effect is applied based on an horizontal and vertical translations, ranging from -1.0 to 1.0. This translation is provided by an external TranslationUpdater. The library includes some:

  • SensorTranslationUpdater: Updates the translation based on the orientation sensors (roll and pitch).
  • AnimatedTranslationUpdater: Applies the translation automatically as a continuous animation.

Customize

Parallax offset

You can change the default offset for the effect within your xml with the attributes parallaxOffsetBase and parallaxOffsetIncrement:

<com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:parallaxOffsetBase="10dp"
  app:parallaxOffsetIncrement="5dp">

The defaul values are 10dp for the base and 5dp for the increment

Vertical and horizontal effect scale

Sometimes you might want to reduce or increase the effect for vertical or horizontal movement.

<com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

app:parallaxScaleVertical="0.25"

>

In this example the views will move vertically a 25% with respect to what they move horizontally.

Note: The parallax scale doesn't scale the views, but rather the parallax movement

Custom Z index

By default the parallax effect is applied in the views Z index. This means that the last view in the layout will be the one closer to the user, and so it will move less; and the first view will be the furthest and will move more.

If you need a different parallax order you can change this behavior by overriding the views index with the attribute layout_parallaxZIndex:

<com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<View

android:id="@+id/layer_2"

android:layout_width="180dp"

android:layout_height="180dp"

android:background="@color/colorPrimaryDark"

app:layout_parallaxZIndex="1" />

<View

android:id="@+id/layer_3"

android:layout_width="120dp"

android:layout_height="120dp"

android:background="@color/colorPrimary"

app:layout_parallaxZIndex="2" />

<View

android:id="@+id/layer_1"

android:layout_width="80dp"

android:layout_height="80dp"

android:background="@color/colorAccent"

app:layout_parallaxZIndex="0" />  </com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout>

Static layer

You can disable the parallax effect in any of the views to stop them from moving with the attribute layout_parallaxEnabled:

<View
  android:id="@+id/layer_static"
  android:layout_width="180dp"
  android:layout_height="180dp"
  android:background="@color/colorPrimaryDark"
  app:layout_parallaxEnabled="false" />

Contribute

For bugs, requests, questions and discussions please use Github Issues.

Attributions

This library was developed by Rafa Vázquez with the idea of moving images from Alex Bailón for the Infojobs' Android application.

Device requirements

This layout needs a gyroscope powered device. Sadly, there are some low-end phones that doesn't have it. In that case, the layered will appear like a static image.

License

Copyright 2016 Schibsted Classified Media Spain S.L.
Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

A SQLite statement builder for Java and Android.

A single adapter implementation for any scrolling view or ViewGroup.

This library consolidates the differences between BaseAdapter, RecyclerView.Adapter, PagerAdapter, and binding to ViewGroup into one unified API.

A powerful debug module that is fully pluggable, extendable, and very useful. It enables you to create your own Critter that contain UI elements which enable you configure your application on the fly.

It also can inject a right-facing DrawerLayout into your activity on top of all other content, making it very unobtrusive and accessible from everywhere within your application.

This is a simple small class that renders a progress in form of an filling arc shape. A progress text can be rendered additionally. This text is rendered in the secondary color for the 'done' area of the arc.

This library is created for get post and information from a blog or a website created with WordPress.

A sticker view for android application.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes