├── stretchTopViewExamples
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── drawable
│ │ │ ├── img1.png
│ │ │ ├── img2.png
│ │ │ ├── img3.png
│ │ │ └── activity_background.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── layout
│ │ │ ├── stretch_top_img.xml
│ │ │ ├── stretch_top_vp.xml
│ │ │ ├── adapter_images.xml
│ │ │ ├── view_bottom.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_stretch_img.xml
│ │ │ └── activity_stretch_vp.xml
│ │ └── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── java
│ │ └── hu
│ │ │ └── lacroix82
│ │ │ └── stretchtopview
│ │ │ ├── activities
│ │ │ ├── MainActivity.java
│ │ │ ├── ExampleImageStretchActivity.java
│ │ │ └── ExampleViewpagerStretchActivity.java
│ │ │ ├── adapters
│ │ │ └── ImageViewAdapter.java
│ │ │ ├── Globals.java
│ │ │ └── Screen.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── runConfigurations.xml
├── modules.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── stretchTopViewLibrary
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── hu
│ │ └── lacroix82
│ │ └── stretchtopviewlibrary
│ │ └── StretchTopScrollView.java
├── build.gradle
└── proguard-rules.pro
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/stretchTopViewExamples/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':stretchTopViewExamples', ':stretchTopViewLibrary'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StretchScrollbarExample
3 |
4 |
--------------------------------------------------------------------------------
/stretchTopViewLibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StretchTopView Library
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/drawable/img1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/drawable/img1.png
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/drawable/img2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/drawable/img2.png
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/drawable/img3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/drawable/img3.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/klaszlo8207/StretchTopViewExample/HEAD/stretchTopViewExamples/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/stretchTopViewLibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/drawable/activity_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/stretch_top_img.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/stretch_top_vp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/adapter_images.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/view_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/stretchTopViewLibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | compile 'com.android.support:appcompat-v7:24.2.1'
27 | }
28 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\lacasrac\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/stretchTopViewLibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\lacasrac\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/java/hu/lacroix82/stretchtopview/activities/MainActivity.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopview.activities;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 |
7 | import hu.lacroix82.stretchscrollbarexample.R;
8 |
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 | }
17 |
18 |
19 | public void imageStretchOpen(View view) {
20 | ExampleImageStretchActivity.open(this);
21 | }
22 |
23 | public void viewpagerStretchOpen(View view) {
24 | ExampleViewpagerStretchActivity.open(this);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/activity_stretch_img.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | applicationId "hu.lacroix82.stretchscrollbarexample"
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | compile 'com.android.support:appcompat-v7:24.2.0'
27 | compile 'com.jakewharton:butterknife:7.0.1'
28 | compile 'com.viewpagerindicator:library:2.4.1@aar'
29 | compile project(path: ':stretchTopViewLibrary')
30 | }
31 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/res/layout/activity_stretch_vp.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
22 |
23 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/java/hu/lacroix82/stretchtopview/activities/ExampleImageStretchActivity.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopview.activities;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.text.Html;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import butterknife.Bind;
11 | import butterknife.ButterKnife;
12 | import hu.lacroix82.stretchscrollbarexample.R;
13 | import hu.lacroix82.stretchtopview.Globals;
14 | import hu.lacroix82.stretchtopviewlibrary.StretchTopScrollView;
15 |
16 | public class ExampleImageStretchActivity extends AppCompatActivity {
17 |
18 | @Bind(R.id.stretchTopView) StretchTopScrollView stretchTopView;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_stretch_img);
24 |
25 | ButterKnife.bind(this);
26 |
27 | init();
28 | }
29 |
30 | private void init() {
31 |
32 | final View bottomView = stretchTopView.getBottomView();
33 |
34 | final TextView descriptionTextView = (TextView) bottomView.findViewById(R.id.descriptionTextView);
35 | descriptionTextView.setText(Html.fromHtml(Globals.DESC));
36 |
37 | stretchTopView.setFactor(1.7f);
38 |
39 | stretchTopView.setChangeListener(new StretchTopScrollView.onOverScrollChanged() {
40 | @Override
41 | public void onChanged(float factor) {
42 | descriptionTextView.setAlpha(factor);
43 | }
44 | });
45 |
46 | }
47 |
48 | public static void open(MainActivity act) {
49 | act.startActivity(new Intent(act, ExampleImageStretchActivity.class));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/java/hu/lacroix82/stretchtopview/adapters/ImageViewAdapter.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopview.adapters;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.PagerAdapter;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.FrameLayout;
9 | import android.widget.ImageView;
10 |
11 | import java.util.ArrayList;
12 |
13 | import hu.lacroix82.stretchscrollbarexample.R;
14 |
15 |
16 | public class ImageViewAdapter extends PagerAdapter {
17 |
18 | private Context mContext;
19 | private ArrayList mDrawableResources;
20 | private LayoutInflater mInflater;
21 |
22 | public ImageViewAdapter(Context c, ArrayList drawableResources) {
23 | mContext = c;
24 | mDrawableResources = drawableResources;
25 | mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
26 | }
27 |
28 | @Override
29 | public int getCount() {
30 | return mDrawableResources.size();
31 | }
32 |
33 | @Override
34 | public boolean isViewFromObject(View view, Object object) {
35 | return view == object;
36 | }
37 |
38 | @Override
39 | public Object instantiateItem(ViewGroup container, final int position) {
40 |
41 | View viewLayout = mInflater.inflate(R.layout.adapter_images, container, false);
42 |
43 | ImageView imageViewPicture = (ImageView) viewLayout.findViewById(R.id.imageViewPicture);
44 | imageViewPicture.setImageDrawable(mContext.getResources().getDrawable(mDrawableResources.get(position)));
45 |
46 | container.addView(viewLayout);
47 |
48 | return viewLayout;
49 | }
50 |
51 | @Override
52 | public void destroyItem(ViewGroup container, int position, Object object) {
53 | container.removeView((FrameLayout) object);
54 |
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/java/hu/lacroix82/stretchtopview/Globals.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopview;
2 |
3 | public class Globals {
4 |
5 | public final static String DESC = "Lorem ipsum dolor sit amet, utroque posidonium duo at, ei pro graece graeci fabulas, ea sit soleat aliquando. Suas facer repudiare mea an. Id menandri definiebas mea, et praesent consetetur sit, mel te eros error quaerendum. Malis scripta tractatos an ius, eos reque dicta voluptaria no.\n" +
6 | "\n" +
7 | "Ea sit esse vero. His commune omnesque complectitur ex. In est idque efficiantur, per ex aeque sapientem, vis nulla habemus ut. In eam solum noster ceteros, timeam periculis incorrupte ut duo. Fastidii mediocrem mea id, aperiam delicata usu ad.\n" +
8 | "\n" +
9 | "Habemus ullamcorper qui ad, modo efficiantur mediocritatem no eos, reque latine usu no. Nec et homero eleifend. Eum ne case maiorum temporibus, sea dolores patrioque no, ne everti viderer pro. Vis dolorem iudicabit ad. Vocent deterruisset quo et, tacimates electram efficiendi an eos.\n" +
10 | "\n" +
11 | "\n " +
12 | "Ea sit esse vero. His commune omnesque complectitur ex. In est idque efficiantur, per ex aeque sapientem, vis nulla habemus ut. In eam solum noster ceteros, timeam periculis incorrupte ut duo. Fastidii mediocrem mea id, aperiam delicata usu ad.\n" +
13 | "\n" +
14 | "Habemus ullamcorper qui ad, modo efficiantur mediocritatem no eos, reque latine usu no. Nec et homero eleifend. Eum ne case maiorum temporibus, sea dolores patrioque no, ne everti viderer pro. Vis dolorem iudicabit ad. Vocent deterruisset quo et, tacimates electram efficiendi an eos.\n" +
15 | "\n" +
16 | "Falli paulo expetenda pro an, an nec fabellas menandri imperdiet. Ei vis erat feugait, et eam tantas causae animal. Pro novum appetere consequuntur ex. Duo ex alterum offendit salutandi, pri eu reque tation." +
17 | "\n ";
18 | }
19 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/java/hu/lacroix82/stretchtopview/Screen.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopview;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.content.res.Resources;
6 | import android.util.DisplayMetrics;
7 | import android.view.Display;
8 | import android.view.WindowManager;
9 |
10 | public class Screen {
11 |
12 | private Screen() {}
13 |
14 | public static int getStatusBarHeight(Context c) {
15 | int result = 0;
16 | int resourceId = c.getResources().getIdentifier("status_bar_height", "dimen", "android");
17 | if (resourceId > 0) {
18 | result = c.getResources().getDimensionPixelSize(resourceId);
19 | }
20 |
21 | return result;
22 | }
23 |
24 | public static int getScreenOrientation(Context mycontext) {
25 | return mycontext.getResources().getConfiguration().orientation;
26 | }
27 |
28 | public static int pxToDp(Context c, int px) {
29 | DisplayMetrics displayMetrics = c.getResources().getDisplayMetrics();
30 | int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
31 | return dp;
32 | }
33 |
34 | public static float dp2px(Context context, float dp) {
35 | Resources resources = context.getResources();
36 | DisplayMetrics metrics = resources.getDisplayMetrics();
37 | float px = dp * (metrics.densityDpi / 160f);
38 | return px;
39 | }
40 |
41 | public static int getDisplayWidth(Context c) {
42 | WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
43 | Display display = window.getDefaultDisplay();
44 | int width = display.getWidth();
45 | int height = display.getHeight();
46 | int orientation = getScreenOrientation(c);
47 | if (orientation != Configuration.ORIENTATION_PORTRAIT) return width;
48 | else return height;
49 | }
50 |
51 | public static int getDisplayHeight(Context c) {
52 | WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
53 | Display display = window.getDefaultDisplay();
54 | int width = display.getWidth();
55 | int height = display.getHeight();
56 | int orientation = getScreenOrientation(c);
57 | if (orientation != Configuration.ORIENTATION_PORTRAIT) return height;
58 | else return width;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/stretchTopViewExamples/src/main/java/hu/lacroix82/stretchtopview/activities/ExampleViewpagerStretchActivity.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopview.activities;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v4.view.ViewPager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.text.Html;
8 | import android.widget.FrameLayout;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | import com.viewpagerindicator.CirclePageIndicator;
13 |
14 | import java.util.ArrayList;
15 |
16 | import butterknife.Bind;
17 | import butterknife.ButterKnife;
18 | import hu.lacroix82.stretchscrollbarexample.R;
19 | import hu.lacroix82.stretchtopview.Globals;
20 | import hu.lacroix82.stretchtopview.adapters.ImageViewAdapter;
21 | import hu.lacroix82.stretchtopviewlibrary.StretchTopScrollView;
22 |
23 | public class ExampleViewpagerStretchActivity extends AppCompatActivity {
24 |
25 | @Bind(R.id.stretchTopView)
26 | StretchTopScrollView stretchTopView;
27 | private ArrayList drawables = new ArrayList<>();
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_stretch_vp);
33 |
34 | ButterKnife.bind(this);
35 |
36 | init();
37 | }
38 |
39 | private void init() {
40 |
41 | final FrameLayout topView = (FrameLayout)stretchTopView.getTopView();
42 | final LinearLayout bottomView = (LinearLayout)stretchTopView.getBottomView();
43 |
44 | final CirclePageIndicator indicator = (CirclePageIndicator) topView.getChildAt(1);
45 |
46 | TextView descriptionTextView = (TextView) bottomView.findViewById(R.id.descriptionTextView);
47 | descriptionTextView.setText(Html.fromHtml(Globals.DESC));
48 |
49 | stretchTopView.setFactor(1.5f);
50 |
51 | stretchTopView.setChangeListener(new StretchTopScrollView.onOverScrollChanged() {
52 | @Override
53 | public void onChanged(float factor) {
54 | indicator.setAlpha(factor);
55 | }
56 | });
57 |
58 | addDatasToViewPager((ViewPager) topView.getChildAt(0), indicator);
59 | }
60 |
61 | private void addDatasToViewPager(ViewPager vp, CirclePageIndicator indicator) {
62 | for (int i = 0; i < 3; i++) {
63 | int res = getResources().getIdentifier("img" + (i + 1), "drawable", this.getPackageName());
64 | drawables.add(res);
65 | }
66 |
67 | ImageViewAdapter adapter = new ImageViewAdapter(this, drawables);
68 | vp.setAdapter(adapter);
69 | indicator.setViewPager(vp);
70 | }
71 |
72 | public static void open(MainActivity act) {
73 | act.startActivity(new Intent(act, ExampleViewpagerStretchActivity.class));
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Tinder like ANDROID stretch top ScrollView
2 |
3 | or just
4 |
5 | ## Pull to zoom:
6 |
7 | This is a **Tinder** like **android Stretch Top ScrollView** / **pull to zoom** custom View..
8 | The Examples show you how can you use this type of view
9 |
10 | ## Gifs:
11 |
12 |
13 |  
14 |
15 | ## Usage for a top ImageView in xml:
16 |
17 | ```java
18 |
19 |
25 |
26 |
31 |
32 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | ```
46 |
47 | ## Usage for a top ViewPager in xml:
48 |
49 | ```java
50 |
51 |
56 |
57 |
61 |
62 |
67 |
68 |
71 |
72 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | ```
88 |
89 | ## after just use in code:
90 |
91 | ```java
92 | stretchTopView.setFactor(1.7f);
93 |
94 | stretchTopView.setChangeListener(new StretchTopScrollView.onOverScrollChanged() {
95 | @Override
96 | public void onChanged(float factor) {
97 | descriptionTextView.setAlpha(factor);
98 | }
99 | });
100 |
101 | ```
102 |
103 | **.setFactor(float v)** : a float factor for the stretch, between 1.0f and maybe 2.0f, optional, default is 1.6f
104 |
105 | **.setChangeListener(...)** : a simple callback that can return the animated factor in a float : 0-100%, between 0f and 1f
106 |
107 |
108 | ## Author:
109 |
110 | **created** by Kozári László
111 |
112 | ## License:
113 |
114 | **Copyright** 2016 Kozári László
115 |
116 | Licensed under the Apache License, Version 2.0 (the "License")
117 |
118 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/stretchTopViewLibrary/src/main/java/hu/lacroix82/stretchtopviewlibrary/StretchTopScrollView.java:
--------------------------------------------------------------------------------
1 | package hu.lacroix82.stretchtopviewlibrary;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.MotionEvent;
6 | import android.view.View;
7 | import android.view.animation.Animation;
8 | import android.view.animation.Transformation;
9 | import android.widget.AbsListView;
10 | import android.widget.AbsListView.OnScrollListener;
11 | import android.widget.LinearLayout;
12 | import android.widget.ScrollView;
13 |
14 | /**
15 | * Created by Kozari Laszlo
16 | */
17 |
18 | public class StretchTopScrollView extends ScrollView implements OnScrollListener {
19 |
20 | private View mTopView, mBottomView;
21 | private int mNormalHeight, mMaxHeight;
22 | private onOverScrollChanged mChangeListener;
23 | private float mFactor = 1.6f;
24 |
25 | private interface OnTouchEventListener {
26 | void onTouchEvent(MotionEvent ev);
27 | }
28 |
29 | public StretchTopScrollView(Context context, AttributeSet attrs, int defStyle) {
30 | super(context, attrs, defStyle);
31 | }
32 |
33 | public StretchTopScrollView(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | }
36 |
37 | public StretchTopScrollView(Context context) {
38 | super(context);
39 | }
40 |
41 | public void setFactor(float f) {
42 | mFactor = f;
43 |
44 | mTopView.postDelayed(new Runnable() {
45 | @Override
46 | public void run() {
47 | mNormalHeight = mTopView.getHeight();
48 | mMaxHeight = (int) (mNormalHeight * mFactor);
49 | }
50 | }, 50);
51 | }
52 |
53 | public View getTopView() {
54 | return mTopView;
55 | }
56 |
57 | public View getBottomView() {
58 | return mBottomView;
59 | }
60 |
61 | @Override
62 | public void onFinishInflate() {
63 | super.onFinishInflate();
64 |
65 | if (getChildCount() > 1)
66 | throw new IllegalArgumentException("Root layout must be a LinearLayout, and only one child on this view!");
67 |
68 | if (getChildCount() == 0 || !(getChildAt(0) instanceof LinearLayout))
69 | throw new IllegalArgumentException("Root layout is not a LinearLayout!");
70 |
71 | if (getChildCount() == 1 && (getChildAt(0) instanceof LinearLayout)) {
72 | LinearLayout parent = (LinearLayout) getChildAt(0);
73 |
74 | if (parent.getChildCount() != 2) {
75 | throw new IllegalArgumentException("Root LinearLayout's has not EXACTLY two Views!");
76 | } else {
77 | mTopView = parent.getChildAt(0);
78 | mBottomView = parent.getChildAt(1);
79 |
80 | mTopView.postDelayed(new Runnable() {
81 | @Override
82 | public void run() {
83 | mNormalHeight = mTopView.getHeight();
84 | mMaxHeight = (int) (mNormalHeight * mFactor);
85 | }
86 | }, 50);
87 | }
88 | }
89 |
90 | }
91 |
92 | @Override
93 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
94 | super.onLayout(changed, l, t, r, b);
95 | }
96 |
97 | @Override
98 | public void onScrollStateChanged(AbsListView view, int scrollState) {
99 | }
100 |
101 | @Override
102 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
103 | int scrollY, int scrollRangeX, int scrollRangeY,
104 | int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
105 |
106 | if (scrollY == 0) {
107 | //down, zoom in
108 | if (deltaY < 0 && mTopView.getLayoutParams().height + Math.abs(deltaY) > mMaxHeight) {
109 | mTopView.getLayoutParams().height = mMaxHeight;
110 | } else if (deltaY < 0 && mTopView.getLayoutParams().height + Math.abs(deltaY) <= mMaxHeight) {
111 | mTopView.getLayoutParams().height += Math.abs(deltaY);
112 | }
113 | //up, zoom out
114 | else if (deltaY > 0 && mTopView.getLayoutParams().height - Math.abs(deltaY) < mNormalHeight) {
115 | mTopView.getLayoutParams().height = mNormalHeight;
116 | } else if (deltaY > 0 && mTopView.getLayoutParams().height - Math.abs(deltaY) >= mNormalHeight) {
117 | mTopView.getLayoutParams().height -= Math.abs(deltaY);
118 | }
119 | }
120 |
121 | if (mChangeListener != null) mChangeListener.onChanged(
122 | (mMaxHeight - (float) mTopView.getLayoutParams().height) / (mMaxHeight - mNormalHeight)
123 | );
124 |
125 | if (deltaY != 0 && scrollY == 0) {
126 | mTopView.requestLayout();
127 | mBottomView.requestLayout();
128 | }
129 |
130 | if (mTopView.getLayoutParams().height == mNormalHeight) {
131 | super.overScrollBy(deltaX, deltaY, scrollX,
132 | scrollY, scrollRangeX, scrollRangeY,
133 | maxOverScrollX, maxOverScrollY, isTouchEvent);
134 | }
135 |
136 | return true;
137 | }
138 |
139 | @Override
140 | public void onScroll(AbsListView view, int firstVisibleItem,
141 | int visibleItemCount, int totalItemCount) {
142 | }
143 |
144 | @Override
145 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
146 | super.onScrollChanged(l, t, oldl, oldt);
147 | }
148 |
149 | @Override
150 | public boolean onTouchEvent(MotionEvent ev) {
151 | touchListener.onTouchEvent(ev);
152 | return super.onTouchEvent(ev);
153 | }
154 |
155 | public interface onOverScrollChanged {
156 | void onChanged(float v);
157 | }
158 |
159 | public void setChangeListener(onOverScrollChanged changeListener) {
160 | mChangeListener = changeListener;
161 | }
162 |
163 | private OnTouchEventListener touchListener = new OnTouchEventListener() {
164 | @Override
165 | public void onTouchEvent(MotionEvent ev) {
166 | if (ev.getAction() == MotionEvent.ACTION_UP) {
167 | if (mTopView != null && mTopView.getHeight() > mNormalHeight) {
168 | ResetAnimation animation = new ResetAnimation(mTopView, mNormalHeight);
169 | animation.setDuration(400);
170 | mTopView.startAnimation(animation);
171 | }
172 | }
173 | }
174 | };
175 |
176 | public class ResetAnimation extends Animation {
177 | int targetHeight;
178 | int originalHeight;
179 | int extraHeight;
180 | View mView;
181 |
182 | ResetAnimation(View view, int targetHeight) {
183 | this.mView = view;
184 | this.targetHeight = targetHeight;
185 | originalHeight = view.getHeight();
186 | extraHeight = this.targetHeight - originalHeight;
187 | }
188 |
189 | @Override
190 | protected void applyTransformation(float interpolatedTime, Transformation t) {
191 | int newHeight = (int) (targetHeight - extraHeight * (1 - interpolatedTime));
192 | mView.getLayoutParams().height = newHeight;
193 | mView.requestLayout();
194 |
195 | if (mChangeListener != null) mChangeListener.onChanged(
196 | (mMaxHeight - (float) mTopView.getLayoutParams().height) / (mMaxHeight - mNormalHeight)
197 | );
198 |
199 | }
200 | }
201 | }
202 |
--------------------------------------------------------------------------------