├── .gitignore
├── LICENSE
├── ParallaxScroll
├── AndroidManifest.xml
├── build.gradle
├── proguard-project.txt
├── project.properties
├── res
│ └── values
│ │ ├── about_libraries_def.xml
│ │ └── attrs.xml
└── src
│ └── com
│ └── nirhart
│ └── parallaxscroll
│ └── views
│ ├── ParallaxExpandableListView.java
│ ├── ParallaxListView.java
│ ├── ParallaxListViewHelper.java
│ ├── ParallaxScrollView.java
│ └── ParallaxedView.java
├── ParallaxScrollExample
├── AndroidManifest.xml
├── build.gradle
├── libs
│ └── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-xhdpi
│ │ ├── github.png
│ │ └── ic_launcher.png
│ ├── drawable
│ │ └── item_background.xml
│ ├── layout
│ │ ├── activity_main.xml
│ │ ├── expand_list_multiple_parallax.xml
│ │ ├── expand_list_one_parallax.xml
│ │ ├── item.xml
│ │ ├── item_child.xml
│ │ ├── list_multiple_parallax.xml
│ │ ├── list_one_parallax.xml
│ │ ├── scroll_multiple_parallax.xml
│ │ ├── scroll_one_parallax.xml
│ │ └── scroll_one_parallax_alpha.xml
│ ├── menu
│ │ └── main.xml
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── nirhart
│ └── parallaxscrollexample
│ ├── CustomExpandableListAdapter.java
│ ├── CustomListAdapter.java
│ ├── MainActivity.java
│ ├── MultipleParallaxExpandableListView.java
│ ├── MultipleParallaxListView.java
│ ├── MultipleParallaxScrollView.java
│ ├── SingleParallaxAlphaScrollView.java
│ ├── SingleParallaxExpandableListView.java
│ ├── SingleParallaxListView.java
│ └── SingleParallaxScrollView.java
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | **/build/
15 |
16 | # Local configuration file (sdk path, etc)
17 | local.properties
18 |
19 | # Eclipse project files
20 | .classpath
21 | .project
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Intellij project files
27 | *.iml
28 | *.ipr
29 | *.iws
30 | .idea/
31 |
32 | # Gradle
33 | .gradle/
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Nir Hartmann
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/ParallaxScroll/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ParallaxScroll/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion '25.0.3'
6 |
7 | compileOptions {
8 | sourceCompatibility JavaVersion.VERSION_1_7
9 | targetCompatibility JavaVersion.VERSION_1_7
10 | }
11 |
12 | sourceSets {
13 | main {
14 | manifest {
15 | srcFile 'AndroidManifest.xml'
16 | }
17 | java {
18 | srcDir 'src'
19 | }
20 | res {
21 | srcDir 'res'
22 | }
23 | assets {
24 | srcDir 'assets'
25 | }
26 | resources {
27 | srcDir 'src'
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/ParallaxScroll/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/ParallaxScroll/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/ParallaxScroll/res/values/about_libraries_def.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Nir Hartmann
5 | https://github.com/nirhart
6 | parallaxscroll
7 | Parallax ListView and ScrollView for Android.
8 | 1.0
9 | https://github.com/nirhart/ParallaxScroll
10 | mit
11 | true
12 | https://github.com/nirhart/ParallaxScroll.git
13 |
14 |
--------------------------------------------------------------------------------
/ParallaxScroll/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ParallaxScroll/src/com/nirhart/parallaxscroll/views/ParallaxExpandableListView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscroll.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.widget.ExpandableListView;
7 |
8 | public class ParallaxExpandableListView extends ExpandableListView {
9 |
10 | private ParallaxListViewHelper helper;
11 |
12 | public ParallaxExpandableListView(Context context, AttributeSet attrs, int defStyle) {
13 | super(context, attrs, defStyle);
14 | init(context, attrs);
15 | }
16 |
17 | public ParallaxExpandableListView(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | init(context, attrs);
20 | }
21 |
22 | protected void init(Context context, AttributeSet attrs) {
23 | helper = new ParallaxListViewHelper(context, attrs, this);
24 | super.setOnScrollListener(helper);
25 | }
26 |
27 | @Override
28 | public void setOnScrollListener(OnScrollListener l) {
29 | helper.setOnScrollListener(l);
30 | }
31 |
32 | public void addParallaxedHeaderView(View v) {
33 | super.addHeaderView(v);
34 | helper.addParallaxedHeaderView(v);
35 | }
36 |
37 | public void addParallaxedHeaderView(View v, Object data, boolean isSelectable) {
38 | super.addHeaderView(v, data, isSelectable);
39 | helper.addParallaxedHeaderView(v, data, isSelectable);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ParallaxScroll/src/com/nirhart/parallaxscroll/views/ParallaxListView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscroll.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.widget.ListView;
7 |
8 | public class ParallaxListView extends ListView {
9 |
10 | private ParallaxListViewHelper helper;
11 |
12 | public ParallaxListView(Context context, AttributeSet attrs, int defStyle) {
13 | super(context, attrs, defStyle);
14 | init(context, attrs);
15 | }
16 |
17 | public ParallaxListView(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | init(context, attrs);
20 | }
21 |
22 | protected void init(Context context, AttributeSet attrs) {
23 | helper = new ParallaxListViewHelper(context, attrs, this);
24 | super.setOnScrollListener(helper);
25 | }
26 |
27 | @Override
28 | public void setOnScrollListener(OnScrollListener l) {
29 | helper.setOnScrollListener(l);
30 | }
31 |
32 | public void addParallaxedHeaderView(View v) {
33 | super.addHeaderView(v);
34 | helper.addParallaxedHeaderView(v);
35 | }
36 |
37 | public void addParallaxedHeaderView(View v, Object data, boolean isSelectable) {
38 | super.addHeaderView(v, data, isSelectable);
39 | helper.addParallaxedHeaderView(v, data, isSelectable);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ParallaxScroll/src/com/nirhart/parallaxscroll/views/ParallaxListViewHelper.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscroll.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.view.animation.TranslateAnimation;
8 | import android.widget.AbsListView;
9 | import android.widget.AbsListView.OnScrollListener;
10 | import android.widget.ListView;
11 |
12 | import com.nirhart.parallaxscroll.R;
13 |
14 | public class ParallaxListViewHelper implements OnScrollListener {
15 |
16 | private static final float DEFAULT_ALPHA_FACTOR = -1F;
17 | private static final float DEFAULT_PARALLAX_FACTOR = 1.9F;
18 | private static final boolean DEFAULT_IS_CIRCULAR = false;
19 | private float parallaxFactor = DEFAULT_PARALLAX_FACTOR;
20 | private float alphaFactor = DEFAULT_ALPHA_FACTOR;
21 | private ParallaxedView parallaxedView;
22 | private boolean isCircular;
23 | private OnScrollListener listener = null;
24 | private ListView listView;
25 |
26 | protected ParallaxListViewHelper(Context context, AttributeSet attrs, ListView listView) {
27 | init(context, attrs, listView);
28 | }
29 |
30 | protected void init(Context context, AttributeSet attrs, ListView listView) {
31 | this.listView = listView;
32 | TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.ParallaxScroll);
33 | this.parallaxFactor = typeArray.getFloat(R.styleable.ParallaxScroll_parallax_factor, DEFAULT_PARALLAX_FACTOR);
34 | this.alphaFactor = typeArray.getFloat(R.styleable.ParallaxScroll_alpha_factor, DEFAULT_ALPHA_FACTOR);
35 | this.isCircular = typeArray.getBoolean(R.styleable.ParallaxScroll_circular_parallax, DEFAULT_IS_CIRCULAR);
36 | typeArray.recycle();
37 | }
38 |
39 | protected void setOnScrollListener(OnScrollListener l) {
40 | this.listener = l;
41 | }
42 |
43 | protected void addParallaxedHeaderView(View v) {
44 | addParallaxedView(v);
45 | }
46 |
47 | protected void addParallaxedHeaderView(View v, Object data, boolean isSelectable) {
48 | addParallaxedView(v);
49 | }
50 |
51 | protected void addParallaxedView(View v) {
52 | this.parallaxedView = new ListViewParallaxedItem(v);
53 | }
54 |
55 | protected void parallaxScroll() {
56 | if (isCircular)
57 | circularParallax();
58 | else
59 | headerParallax();
60 | }
61 |
62 | private void circularParallax() {
63 | if (listView.getChildCount() > 0) {
64 | int top = -listView.getChildAt(0).getTop();
65 | if (top >= 0) {
66 | fillParallaxedViews();
67 | setFilters(top);
68 | }
69 | }
70 | }
71 |
72 | private void headerParallax() {
73 | if (parallaxedView != null) {
74 | if (listView.getChildCount() > 0) {
75 | int top = -listView.getChildAt(0).getTop();
76 | if (top >= 0) {
77 | setFilters(top);
78 | }
79 | }
80 | }
81 | }
82 |
83 | private void setFilters(int top) {
84 | parallaxedView.setOffset((float)top / parallaxFactor);
85 | if (alphaFactor != DEFAULT_ALPHA_FACTOR) {
86 | float alpha = (top <= 0) ? 1 : (100 / ((float)top * alphaFactor));
87 | parallaxedView.setAlpha(alpha);
88 | }
89 | parallaxedView.animateNow();
90 | }
91 |
92 | private void fillParallaxedViews() {
93 | if (parallaxedView == null || parallaxedView.is(listView.getChildAt(0)) == false) {
94 | if (parallaxedView != null) {
95 | resetFilters();
96 | parallaxedView.setView(listView.getChildAt(0));
97 | } else {
98 | parallaxedView = new ListViewParallaxedItem(listView.getChildAt(0));
99 | }
100 | }
101 | }
102 |
103 | private void resetFilters() {
104 | parallaxedView.setOffset(0);
105 | if (alphaFactor != DEFAULT_ALPHA_FACTOR)
106 | parallaxedView.setAlpha(1F);
107 | parallaxedView.animateNow();
108 | }
109 |
110 | @Override
111 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
112 | parallaxScroll();
113 | if (this.listener != null)
114 | this.listener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
115 | }
116 |
117 | @Override
118 | public void onScrollStateChanged(AbsListView view, int scrollState) {
119 | if (this.listener != null)
120 | this.listener.onScrollStateChanged(view, scrollState);
121 | }
122 |
123 | protected class ListViewParallaxedItem extends ParallaxedView {
124 |
125 | public ListViewParallaxedItem(View view) {
126 | super(view);
127 | }
128 |
129 | @Override
130 | protected void translatePreICS(View view, float offset) {
131 | addAnimation(new TranslateAnimation(0, 0, offset, offset));
132 | }
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/ParallaxScroll/src/com/nirhart/parallaxscroll/views/ParallaxScrollView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscroll.views;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ScrollView;
11 |
12 | import com.nirhart.parallaxscroll.R;
13 |
14 | public class ParallaxScrollView extends ScrollView {
15 |
16 | private static final int DEFAULT_PARALLAX_VIEWS = 1;
17 | private static final float DEFAULT_INNER_PARALLAX_FACTOR = 1.9F;
18 | private static final float DEFAULT_PARALLAX_FACTOR = 1.9F;
19 | private static final float DEFAULT_ALPHA_FACTOR = -1F;
20 | private int numOfParallaxViews = DEFAULT_PARALLAX_VIEWS;
21 | private float innerParallaxFactor = DEFAULT_PARALLAX_FACTOR;
22 | private float parallaxFactor = DEFAULT_PARALLAX_FACTOR;
23 | private float alphaFactor = DEFAULT_ALPHA_FACTOR;
24 | private ArrayList parallaxedViews = new ArrayList();
25 |
26 | public ParallaxScrollView(Context context, AttributeSet attrs, int defStyle) {
27 | super(context, attrs, defStyle);
28 | init(context, attrs);
29 | }
30 |
31 | public ParallaxScrollView(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | init(context, attrs);
34 | }
35 |
36 | public ParallaxScrollView(Context context) {
37 | super(context);
38 | }
39 |
40 | protected void init(Context context, AttributeSet attrs) {
41 | TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.ParallaxScroll);
42 | this.parallaxFactor = typeArray.getFloat(R.styleable.ParallaxScroll_parallax_factor, DEFAULT_PARALLAX_FACTOR);
43 | this.alphaFactor = typeArray.getFloat(R.styleable.ParallaxScroll_alpha_factor, DEFAULT_ALPHA_FACTOR);
44 | this.innerParallaxFactor = typeArray.getFloat(R.styleable.ParallaxScroll_inner_parallax_factor, DEFAULT_INNER_PARALLAX_FACTOR);
45 | this.numOfParallaxViews = typeArray.getInt(R.styleable.ParallaxScroll_parallax_views_num, DEFAULT_PARALLAX_VIEWS);
46 | typeArray.recycle();
47 | }
48 |
49 | @Override
50 | protected void onFinishInflate() {
51 | super.onFinishInflate();
52 | makeViewsParallax();
53 | }
54 |
55 | private void makeViewsParallax() {
56 | if (getChildCount() > 0 && getChildAt(0) instanceof ViewGroup) {
57 | ViewGroup viewsHolder = (ViewGroup) getChildAt(0);
58 | int numOfParallaxViews = Math.min(this.numOfParallaxViews, viewsHolder.getChildCount());
59 | for (int i = 0; i < numOfParallaxViews; i++) {
60 | ParallaxedView parallaxedView = new ScrollViewParallaxedItem(viewsHolder.getChildAt(i));
61 | parallaxedViews.add(parallaxedView);
62 | }
63 | }
64 | }
65 |
66 | @Override
67 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
68 | super.onScrollChanged(l, t, oldl, oldt);
69 | float parallax = parallaxFactor;
70 | float alpha = alphaFactor;
71 | for (ParallaxedView parallaxedView : parallaxedViews) {
72 | parallaxedView.setOffset(((float)t / parallax), Math.round(t/parallaxFactor));
73 | parallax *= innerParallaxFactor;
74 | if (alpha != DEFAULT_ALPHA_FACTOR) {
75 | float fixedAlpha = (t <= 0) ? 1 : (100 / ((float)t * alpha));
76 | parallaxedView.setAlpha(fixedAlpha);
77 | alpha /= alphaFactor;
78 | }
79 | parallaxedView.animateNow();
80 | }
81 | }
82 |
83 | protected class ScrollViewParallaxedItem extends ParallaxedView {
84 |
85 | public ScrollViewParallaxedItem(View view) {
86 | super(view);
87 | }
88 |
89 | @Override
90 | protected void translatePreICS(View view, float offset) {
91 | view.offsetTopAndBottom((int)offset - lastOffset);
92 | lastOffset = (int)offset;
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/ParallaxScroll/src/com/nirhart/parallaxscroll/views/ParallaxedView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscroll.views;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.graphics.Rect;
5 | import android.os.Build;
6 | import android.view.View;
7 | import android.view.animation.AlphaAnimation;
8 | import android.view.animation.Animation;
9 | import android.view.animation.AnimationSet;
10 |
11 | import java.lang.ref.WeakReference;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | public abstract class ParallaxedView {
16 | private static boolean isAPI11 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
17 | private static boolean isAPI18 = Build.VERSION.SDK_INT >= 18;
18 | protected WeakReference view;
19 | protected int lastOffset;
20 | protected List animations;
21 | protected Rect clippingRect = new Rect();
22 | protected boolean firstRectGet = false;
23 | private int lastScrollY;
24 |
25 | abstract protected void translatePreICS(View view, float offset);
26 |
27 | public ParallaxedView(View view) {
28 | this.lastOffset = 0;
29 | this.animations = new ArrayList();
30 | this.view = new WeakReference(view);
31 | }
32 |
33 | public boolean is(View v) {
34 | return (v != null && view != null && view.get() != null && view.get().equals(v));
35 | }
36 |
37 | @SuppressLint("NewApi")
38 | public void setOffset(float offset) {
39 | View view = this.view.get();
40 | if (view != null)
41 | if (isAPI11) {
42 | view.setTranslationY(offset);
43 | } else {
44 | translatePreICS(view, offset);
45 | }
46 | }
47 |
48 | @SuppressLint("NewApi")
49 | public void setOffset(float offset, int originalScrollY) {
50 | View view = this.view.get();
51 | if (view != null)
52 | if (isAPI11) {
53 | if (!firstRectGet) {
54 | clippingRect.top = view.getTop();
55 | clippingRect.left = view.getLeft();
56 | clippingRect.right = view.getRight();
57 | clippingRect.bottom = view.getBottom();
58 | firstRectGet = true;
59 | }
60 | if (lastScrollY == 0) {
61 | lastScrollY = originalScrollY;
62 | }
63 | int delta = lastScrollY - originalScrollY;
64 | clippingRect.bottom += delta;
65 | view.setTranslationY(Math.round(offset));
66 | if (isAPI18) view.setClipBounds(clippingRect);
67 | lastScrollY = originalScrollY;
68 | if (isAPI18) {
69 | if (clippingRect.bottom <= clippingRect.top) {
70 | view.setVisibility(View.INVISIBLE);
71 | } else {
72 | view.setVisibility(View.VISIBLE);
73 | }
74 | }
75 | } else {
76 | translatePreICS(view, offset);
77 | }
78 | }
79 |
80 | public void setAlpha(float alpha) {
81 | View view = this.view.get();
82 | if (view != null)
83 | if (isAPI11) {
84 | view.setAlpha(alpha);
85 | } else {
86 | alphaPreICS(view, alpha);
87 | }
88 | }
89 |
90 | protected synchronized void addAnimation(Animation animation) {
91 | animations.add(animation);
92 | }
93 |
94 | protected void alphaPreICS(View view, float alpha) {
95 | addAnimation(new AlphaAnimation(alpha, alpha));
96 | }
97 |
98 | protected synchronized void animateNow() {
99 | View view = this.view.get();
100 | if (view != null) {
101 | AnimationSet set = new AnimationSet(true);
102 | for (Animation animation : animations)
103 | if (animation != null)
104 | set.addAnimation(animation);
105 | set.setDuration(0);
106 | set.setFillAfter(true);
107 | view.setAnimation(set);
108 | set.start();
109 | animations.clear();
110 | }
111 | }
112 |
113 | public void setView(View view) {
114 | this.view = new WeakReference(view);
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
34 |
35 |
36 |
39 |
40 |
41 |
44 |
45 |
46 |
49 |
50 |
51 |
54 |
55 |
56 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | defaultConfig {
5 | versionCode 6
6 | versionName '1.5.1'
7 |
8 | minSdkVersion 8
9 | targetSdkVersion 25
10 | }
11 |
12 | compileSdkVersion 25
13 | buildToolsVersion '25.0.3'
14 |
15 | sourceSets {
16 | main {
17 | manifest {
18 | srcFile 'AndroidManifest.xml'
19 | }
20 | java {
21 | srcDir 'src'
22 | }
23 | res {
24 | srcDir 'res'
25 | }
26 | assets {
27 | srcDir 'assets'
28 | }
29 | resources {
30 | srcDir 'src'
31 | }
32 | }
33 | }
34 | }
35 | dependencies {
36 | // internal deps (the sub projects dependencies are transitive to this one)
37 | compile project(':ParallaxScroll')
38 | compile 'com.android.support:support-v4:19.0.1'
39 | }
40 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirhart/ParallaxScroll/dd53d1f9d18d097e53e8c2270fa4e77ad439c7a4/ParallaxScrollExample/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/ParallaxScrollExample/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library.reference.1=../ParallaxScroll
16 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/drawable-xhdpi/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirhart/ParallaxScroll/dd53d1f9d18d097e53e8c2270fa4e77ad439c7a4/ParallaxScrollExample/res/drawable-xhdpi/github.png
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirhart/ParallaxScroll/dd53d1f9d18d097e53e8c2270fa4e77ad439c7a4/ParallaxScrollExample/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/drawable/item_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
20 |
21 |
29 |
30 |
38 |
39 |
47 |
48 |
56 |
57 |
65 |
66 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/expand_list_multiple_parallax.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/expand_list_one_parallax.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/item_child.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/list_multiple_parallax.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/list_one_parallax.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/scroll_multiple_parallax.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
24 |
25 |
33 |
34 |
42 |
43 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/scroll_one_parallax.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
22 |
23 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/layout/scroll_one_parallax_alpha.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
14 |
15 |
23 |
24 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ParallaxScrollExample
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/CustomExpandableListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseExpandableListAdapter;
7 | import android.widget.TextView;
8 |
9 | public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
10 |
11 | private LayoutInflater inflater;
12 |
13 | public CustomExpandableListAdapter(LayoutInflater inflater) {
14 | this.inflater = inflater;
15 | }
16 |
17 | @Override
18 | public String getChild(int groupPosition, int childPosition) {
19 | return "Group " + groupPosition + ", child " + childPosition;
20 | }
21 |
22 | @Override
23 | public long getChildId(int groupPosition, int childPosition) {
24 | return 0;
25 | }
26 |
27 | @Override
28 | public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
29 | TextView textView = (TextView) convertView;
30 | if (textView == null)
31 | textView = (TextView) inflater.inflate(R.layout.item_child, null);
32 | textView.setText(getChild(groupPosition, childPosition));
33 | return textView;
34 | }
35 |
36 | @Override
37 | public int getChildrenCount(int groupPosition) {
38 | return groupPosition*2+1;
39 | }
40 |
41 | @Override
42 | public String getGroup(int groupPosition) {
43 | return "Group " + groupPosition;
44 | }
45 |
46 | @Override
47 | public int getGroupCount() {
48 | return 20;
49 | }
50 |
51 | @Override
52 | public long getGroupId(int groupPosition) {
53 | return 0;
54 | }
55 |
56 | @Override
57 | public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
58 | TextView textView = (TextView) convertView;
59 | if (textView == null)
60 | textView = (TextView) inflater.inflate(R.layout.item, null);
61 | textView.setText(getGroup(groupPosition));
62 | return textView;
63 | }
64 |
65 | @Override
66 | public boolean hasStableIds() {
67 | return false;
68 | }
69 |
70 | @Override
71 | public boolean isChildSelectable(int groupPosition, int childPosition) {
72 | return false;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/CustomListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.TextView;
8 |
9 | public class CustomListAdapter extends BaseAdapter {
10 |
11 | private LayoutInflater inflater;
12 |
13 | public CustomListAdapter(LayoutInflater inflater) {
14 | this.inflater = inflater;
15 | }
16 |
17 | @Override
18 | public int getCount() {
19 | return 20;
20 | }
21 |
22 | @Override
23 | public Object getItem(int position) {
24 | return null;
25 | }
26 |
27 | @Override
28 | public long getItemId(int position) {
29 | return 0;
30 | }
31 |
32 | @Override
33 | public View getView(int position, View convertView, ViewGroup parent) {
34 | TextView textView = (TextView) convertView;
35 | if (textView == null)
36 | textView = (TextView) inflater.inflate(R.layout.item, null);
37 | textView.setText("Item " + position);
38 | return textView;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 |
12 | public class MainActivity extends Activity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | }
19 |
20 | public void onSingleScrollParallaxClicked(View v) {
21 | Intent intent = new Intent(this, SingleParallaxScrollView.class);
22 | startActivity(intent);
23 | }
24 |
25 | public void onSingleScrollParallaxAlphaClicked(View v) {
26 | Intent intent = new Intent(this, SingleParallaxAlphaScrollView.class);
27 | startActivity(intent);
28 | }
29 |
30 | public void onMultipleScrollParallaxClicked(View v) {
31 | Intent intent = new Intent(this, MultipleParallaxScrollView.class);
32 | startActivity(intent);
33 | }
34 |
35 | public void onSingleListParallaxClicked(View v) {
36 | Intent intent = new Intent(this, SingleParallaxListView.class);
37 | startActivity(intent);
38 | }
39 |
40 | public void onSingleExpandableListParallaxClicked(View v) {
41 | Intent intent = new Intent(this, SingleParallaxExpandableListView.class);
42 | startActivity(intent);
43 | }
44 |
45 | public void onMultipleExpandableListParallaxClicked(View v) {
46 | Intent intent = new Intent(this, MultipleParallaxExpandableListView.class);
47 | startActivity(intent);
48 | }
49 |
50 | public void onMultipleListParallaxClicked(View v) {
51 | Intent intent = new Intent(this, MultipleParallaxListView.class);
52 | startActivity(intent);
53 | }
54 |
55 | @Override
56 | public boolean onCreateOptionsMenu(Menu menu) {
57 | MenuInflater inflater = getMenuInflater();
58 | inflater.inflate(R.menu.main, menu);
59 | return true;
60 | }
61 |
62 | @Override
63 | public boolean onOptionsItemSelected(MenuItem item) {
64 | if (item.getItemId() == R.id.action_github) {
65 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
66 | startActivity(browserIntent);
67 | }
68 | return true;
69 | }
70 | }
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/MultipleParallaxExpandableListView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.Menu;
9 | import android.view.MenuInflater;
10 | import android.view.MenuItem;
11 |
12 | import com.nirhart.parallaxscroll.views.ParallaxExpandableListView;
13 |
14 | public class MultipleParallaxExpandableListView extends Activity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.expand_list_multiple_parallax);
20 | ParallaxExpandableListView listView = (ParallaxExpandableListView) findViewById(R.id.list_view);
21 | CustomExpandableListAdapter adapter = new CustomExpandableListAdapter(LayoutInflater.from(this));
22 | listView.setAdapter(adapter);
23 | }
24 |
25 | @Override
26 | public boolean onCreateOptionsMenu(Menu menu) {
27 | MenuInflater inflater = getMenuInflater();
28 | inflater.inflate(R.menu.main, menu);
29 | return true;
30 | }
31 |
32 | @Override
33 | public boolean onOptionsItemSelected(MenuItem item) {
34 | if (item.getItemId() == R.id.action_github) {
35 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
36 | startActivity(browserIntent);
37 | }
38 | return true;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/MultipleParallaxListView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.Menu;
9 | import android.view.MenuInflater;
10 | import android.view.MenuItem;
11 |
12 | import com.nirhart.parallaxscroll.views.ParallaxListView;
13 |
14 | public class MultipleParallaxListView extends Activity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.list_multiple_parallax);
20 | ParallaxListView listView = (ParallaxListView) findViewById(R.id.list_view);
21 | CustomListAdapter adapter = new CustomListAdapter(LayoutInflater.from(this));
22 | listView.setAdapter(adapter);
23 | }
24 |
25 | @Override
26 | public boolean onCreateOptionsMenu(Menu menu) {
27 | MenuInflater inflater = getMenuInflater();
28 | inflater.inflate(R.menu.main, menu);
29 | return true;
30 | }
31 |
32 | @Override
33 | public boolean onOptionsItemSelected(MenuItem item) {
34 | if (item.getItemId() == R.id.action_github) {
35 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
36 | startActivity(browserIntent);
37 | }
38 | return true;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/MultipleParallaxScrollView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 |
11 | public class MultipleParallaxScrollView extends Activity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.scroll_multiple_parallax);
17 | }
18 |
19 | @Override
20 | public boolean onCreateOptionsMenu(Menu menu) {
21 | MenuInflater inflater = getMenuInflater();
22 | inflater.inflate(R.menu.main, menu);
23 | return true;
24 | }
25 |
26 | @Override
27 | public boolean onOptionsItemSelected(MenuItem item) {
28 | if (item.getItemId() == R.id.action_github) {
29 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
30 | startActivity(browserIntent);
31 | }
32 | return true;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/SingleParallaxAlphaScrollView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 |
11 | public class SingleParallaxAlphaScrollView extends Activity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.scroll_one_parallax_alpha);
17 | }
18 |
19 | @Override
20 | public boolean onCreateOptionsMenu(Menu menu) {
21 | MenuInflater inflater = getMenuInflater();
22 | inflater.inflate(R.menu.main, menu);
23 | return true;
24 | }
25 |
26 | @Override
27 | public boolean onOptionsItemSelected(MenuItem item) {
28 | if (item.getItemId() == R.id.action_github) {
29 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
30 | startActivity(browserIntent);
31 | }
32 | return true;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/SingleParallaxExpandableListView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.Menu;
10 | import android.view.MenuInflater;
11 | import android.view.MenuItem;
12 | import android.widget.TextView;
13 |
14 | import com.nirhart.parallaxscroll.views.ParallaxExpandableListView;
15 |
16 | public class SingleParallaxExpandableListView extends Activity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.expand_list_one_parallax);
22 | ParallaxExpandableListView listView = (ParallaxExpandableListView) findViewById(R.id.list_view);
23 |
24 | TextView v = new TextView(this);
25 | v.setText("PARALLAXED");
26 | v.setGravity(Gravity.CENTER);
27 | v.setTextSize(40);
28 | v.setHeight(200);
29 | v.setBackgroundResource(R.drawable.item_background);
30 |
31 | listView.addParallaxedHeaderView(v);
32 | CustomExpandableListAdapter adapter = new CustomExpandableListAdapter(LayoutInflater.from(this));
33 | listView.setAdapter(adapter);
34 | }
35 |
36 | @Override
37 | public boolean onCreateOptionsMenu(Menu menu) {
38 | MenuInflater inflater = getMenuInflater();
39 | inflater.inflate(R.menu.main, menu);
40 | return true;
41 | }
42 |
43 | @Override
44 | public boolean onOptionsItemSelected(MenuItem item) {
45 | if (item.getItemId() == R.id.action_github) {
46 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
47 | startActivity(browserIntent);
48 | }
49 | return true;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/SingleParallaxListView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.Menu;
10 | import android.view.MenuInflater;
11 | import android.view.MenuItem;
12 | import android.widget.TextView;
13 |
14 | import com.nirhart.parallaxscroll.views.ParallaxListView;
15 |
16 | public class SingleParallaxListView extends Activity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.list_one_parallax);
22 | ParallaxListView listView = (ParallaxListView) findViewById(R.id.list_view);
23 | CustomListAdapter adapter = new CustomListAdapter(LayoutInflater.from(this));
24 |
25 | TextView v = new TextView(this);
26 | v.setText("PARALLAXED");
27 | v.setGravity(Gravity.CENTER);
28 | v.setTextSize(40);
29 | v.setHeight(200);
30 | v.setBackgroundResource(R.drawable.item_background);
31 |
32 | listView.addParallaxedHeaderView(v);
33 | listView.setAdapter(adapter);
34 | }
35 |
36 | @Override
37 | public boolean onCreateOptionsMenu(Menu menu) {
38 | MenuInflater inflater = getMenuInflater();
39 | inflater.inflate(R.menu.main, menu);
40 | return true;
41 | }
42 |
43 | @Override
44 | public boolean onOptionsItemSelected(MenuItem item) {
45 | if (item.getItemId() == R.id.action_github) {
46 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
47 | startActivity(browserIntent);
48 | }
49 | return true;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ParallaxScrollExample/src/com/nirhart/parallaxscrollexample/SingleParallaxScrollView.java:
--------------------------------------------------------------------------------
1 | package com.nirhart.parallaxscrollexample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 |
11 | public class SingleParallaxScrollView extends Activity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.scroll_one_parallax);
17 | }
18 |
19 | @Override
20 | public boolean onCreateOptionsMenu(Menu menu) {
21 | MenuInflater inflater = getMenuInflater();
22 | inflater.inflate(R.menu.main, menu);
23 | return true;
24 | }
25 |
26 | @Override
27 | public boolean onOptionsItemSelected(MenuItem item) {
28 | if (item.getItemId() == R.id.action_github) {
29 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
30 | startActivity(browserIntent);
31 | }
32 | return true;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Parallax Scrolls
2 | ================
3 | # Parallax ListView and ScrollView for Android
4 |
5 | ## This project includes
6 | * ScrollView with one or more parallaxed views
7 | * ListView with parallaxed header
8 | * Complete parallaxed ListView
9 | * ExpandableListView with parallaxed header
10 | * Complete parallaxed ExpandableListView
11 | * Support Android 1.6 and above
12 |
13 | ## Usage
14 | ### See demo app for best practice - https://play.google.com/store/apps/details?id=com.nirhart.parallaxscrollexample
15 | * parallax_factor - For ScrollView and ListView, the first view's parallax factor
16 | * inner_parallax_factor - For ScrollView only - the parallax factor between each view and view
17 | * parallax_views_num - For ScrollView only - the number of parallaxed views
18 | * circular_parallax - For ListView only - whether all of the list is parallaxed or not
19 |
20 | ## Maven repository access
21 |
22 | ### In the build.gradle (at the module level) add the new dependency:
23 | ```
24 | compile 'com.github.nirhart:parallaxscroll:1.0'
25 | ```
26 |
27 | or look for it using Android Studio module dependencies
28 |
29 | ### Example ParallaxScroll Usage
30 |
31 | ```xml
32 |
39 |
40 |
44 |
45 |
53 |
54 |
62 |
63 |
64 |
65 | ```
66 |
67 | ## Building
68 |
69 | ### Using gradle to build.
70 |
71 | This project uses the gradle wrapper to build the library and example app
72 |
73 | #### assemble the library
74 |
75 | `./gradlew :ParallaxScroll:assembleDebug`
76 |
77 |
78 | #### install the example
79 |
80 | `./gradlew :ParallaxScrollExample:installDebug`
81 |
82 | *note:* on windows use `gradlew.bat` instead of `./gradlew`
83 |
84 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:2.3.0'
7 | }
8 | }
9 |
10 | apply plugin: 'android-reporting'
11 |
12 | /**
13 | * Task to generate a gradle wrapper.
14 | */
15 | task wrapper(type: Wrapper) {
16 | gradleVersion = '1.11'
17 | }
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirhart/ParallaxScroll/dd53d1f9d18d097e53e8c2270fa4e77ad439c7a4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Oct 27 12:53:30 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'ParallaxScroll', 'ParallaxScrollExample'
2 |
--------------------------------------------------------------------------------