Parallax on Android in the simplest way
compile ('com.github.florent37:androidparallax:1.0.1@aar'){
transitive=true
}
Simply replace your ScrollView with a com.github.florent37.parallax.ScrollView
Then add a parallax=FLOAT_VALUE into your view's tag
<com.github.florent37.parallax.ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- ...your usual views... -->
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/background"
android:tag="parallax=0.3" />
<TextView
style="@style/MyTitle"
android:layout_width="match_parent"
android:layout_height="160dp"
android:gravity="center"
android:text="My awesome title"
android:tag="parallax=0.5" />
<!-- ...your usual views... -->
</com.github.florent37.parallax.ScrollView>
And no extra lines into the activity !
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
If you don't want to play with the android:tag attributes, then you cas simple surround your view with a ParallaxView.
A ParallaxView can move vertically of horizontally Parallax attributes defines a parallax factor for this view
- parallaxVertical < 0 : the view will move slower than the scroll
- parallaxVertical > 0 : the view will move faster than the scroll
<com.github.florent37.parallax.ParallaxView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:parallaxVertical="1.1"
>
<!-- Your View -->
</com.github.florent37.parallax.ScrollView>
Horizontal translation
- parallaxHorizontal < 0 : the view will move to the right
- parallaxHorizontal > 0 : the view will move to the left
<com.github.florent37.parallax.ParallaxView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:parallaxHorizontal="1.1"
>
<!-- Your View -->
</com.github.florent37.parallax.ScrollView>
- Add RecyclerView Parallax
- Add fading / parallax effect on a toolbar
Looking for contributors, feel free to fork !
Author: Florent Champigny
![Follow me on Google+](https://raw.githubusercontent.com/florent37/DaVinci/master/mobile/src/main/res/drawable-hdpi/gplus.png)
![Follow me on Twitter](https://raw.githubusercontent.com/florent37/DaVinci/master/mobile/src/main/res/drawable-hdpi/twitter.png)
![Follow me on LinkedIn](https://raw.githubusercontent.com/florent37/DaVinci/master/mobile/src/main/res/drawable-hdpi/linkedin.png)
Copyright 2015 florent37, Inc.
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.