Skip to content

Commit 19d50ab

Browse files
authored
Added feature to disable parallax in specific views (#10)
1 parent ece8a3b commit 19d50ab

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ If you need a different parallax order you can change this behavior by overridin
149149
</com.schibsted.spain.parallaxlayerlayout.ParallaxLayerLayout>
150150
```
151151

152+
## Static layer
153+
154+
You can disable the parallax effect in any of the views to stop them from moving with the attribute **layout_parallaxEnabled**:
155+
156+
```xml
157+
<View
158+
android:id="@+id/layer_static"
159+
android:layout_width="180dp"
160+
android:layout_height="180dp"
161+
android:background="@color/colorPrimaryDark"
162+
app:layout_parallaxEnabled="false" />
163+
```
164+
165+
152166
# Contribute
153167
For bugs, requests, questions and discussions please use [Github Issues](https://github.com/SchibstedSpain/parallax-layer-layout/issues).
154168

library/src/main/java/com/schibsted/spain/parallaxlayerlayout/ParallaxLayerLayout.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public void setTranslationUpdater(TranslationUpdater translationUpdater) {
121121
@Size(2)
122122
private float[] calculateFinalTranslationPx(View child, @Size(2) float[] translations) {
123123
LayoutParams lp = (LayoutParams) child.getLayoutParams();
124+
if (!lp.enabled) {
125+
return new float[] { 0f, 0f };
126+
}
124127
int xSign = translations[0] > 0 ? 1 : -1;
125128
int ySign = translations[1] > 0 ? 1 : -1;
126129

@@ -168,6 +171,7 @@ public static class LayoutParams extends FrameLayout.LayoutParams {
168171
private float offsetPx;
169172
private int customIndex = -1;
170173
private float incrementMultiplier = 1.0f;
174+
private boolean enabled = true;
171175

172176
public LayoutParams(Context c, AttributeSet attrs) {
173177
super(c, attrs);
@@ -178,6 +182,8 @@ public LayoutParams(Context c, AttributeSet attrs) {
178182
a.getInt(R.styleable.ParallaxLayerLayout_LayoutParams_layout_parallaxZIndex, -1);
179183
incrementMultiplier = a.getFloat(
180184
R.styleable.ParallaxLayerLayout_LayoutParams_layout_parallaxIncrementMultiplier, 1.0f);
185+
enabled = a.getBoolean(
186+
R.styleable.ParallaxLayerLayout_LayoutParams_layout_parallaxEnabled, true);
181187
} finally {
182188
a.recycle();
183189
}

library/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
format="integer"/>
1717
<attr name="layout_parallaxIncrementMultiplier"
1818
format="float"/>
19+
<attr name="layout_parallaxEnabled"
20+
format="boolean"/>
1921
</declare-styleable>
2022
</resources>

0 commit comments

Comments
 (0)