├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── dynamicviewpager
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── dynamicviewpager
│ │ │ ├── App.java
│ │ │ ├── Image.kt
│ │ │ ├── ScrollingActivity.kt
│ │ │ ├── SimpleImageFragment.kt
│ │ │ └── TransformViewPagerAdapter.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_review_detail_header.xml
│ │ ├── activity_scrolling.xml
│ │ ├── content_scrolling.xml
│ │ └── fragment_simple_image.xml
│ │ ├── menu
│ │ └── menu_scrolling.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── dynamicviewpager
│ └── ExampleUnitTest.kt
├── build.gradle
├── demo.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── transformviewpager
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── danteandroid
│ └── transformviewpager
│ └── ExampleInstrumentedTest.kt
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── danteandroid
│ │ └── transformviewpager
│ │ ├── TransformViewPager.kt
│ │ ├── Transformable.kt
│ │ └── UiUtils.kt
└── res
│ └── values
│ └── strings.xml
└── test
└── java
└── com
└── danteandroid
└── transformviewpager
└── ExampleUnitTest.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | /.idea/
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TransformViewPager
2 | A dynamic-height viewpager which can transform its pages.
3 |
4 | [](https://jitpack.io/#DanteAndroid/TransformViewPager)
5 |
6 | ## Demonstration
7 |
8 |
9 |
10 | ## Dependency
11 | ```
12 | implementation 'com.github.DanteAndroid:TransformViewPager:v0.1'
13 | ```
14 |
15 | ## Usage
16 | 0. Use `TransformViewPager` which extends ViewPager
17 | 1. Make your data item implement `Transformable`
18 | 2. Make your ViewPager's adapter implement `TransformableAdapter`
19 | 3. Of course set your TransformableAdapter for the TransformViewPager
20 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 29
9 | buildToolsVersion "28.0.3"
10 | defaultConfig {
11 | applicationId "com.danteandroid.transformviewpager"
12 | minSdkVersion 19
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 |
30 | implementation 'com.github.bumptech.glide:glide:4.9.0'
31 | implementation 'com.google.code.gson:gson:2.8.6'
32 |
33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
34 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
35 | implementation 'androidx.appcompat:appcompat:1.1.0'
36 | implementation 'com.google.android.material:material:1.0.0'
37 | implementation project(path: ':transformviewpager')
38 | // implementation 'com.github.DanteAndroid:TransformViewPager:v0.1'
39 | }
40 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/dynamicviewpager/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.example.dynamicviewpager", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/dynamicviewpager/App.java:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Application;
5 | import android.content.Context;
6 |
7 | /**
8 | * @author Dante
9 | * 2019-11-07
10 | */
11 | public class App extends Application {
12 |
13 | @SuppressLint("StaticFieldLeak")
14 | public static Context context;
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | context = this;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/dynamicviewpager/Image.kt:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager
2 |
3 | import com.danteandroid.transformviewpager.Transformable
4 | import java.io.Serializable
5 |
6 | /**
7 | * @author Dante
8 | * 2019-11-07
9 | */
10 | data class Image(
11 | val width: Int,
12 | val height: Int,
13 | val format: String,
14 | val size: Int,
15 | val url: String
16 | ) : Serializable, Transformable {
17 | override fun getOriginalWidth(): Float {
18 | return width.toFloat()
19 | }
20 |
21 | override fun getOrignalHeight(): Float {
22 | return height.toFloat()
23 | }
24 | }
25 |
26 | const val JSON_DATA: String = "[\n" +
27 | "{\n" +
28 | " \"width\": 1000,\n" +
29 | " \"height\": 700,\n" +
30 | " \"format\": \"jpeg\",\n" +
31 | " \"size\": 28340,\n" +
32 | " \"url\": \"https://picsum.photos/id/100/1000/700\"\n" +
33 | "},\n" +
34 | "{\n" +
35 | " \"width\": 1920,\n" +
36 | " \"height\": 1080,\n" +
37 | " \"format\": \"jpeg\",\n" +
38 | " \"size\": 33663,\n" +
39 | " \"url\": \"https://picsum.photos/id/99/1920/1080\"\n" +
40 | "},\n" +
41 | "{\n" +
42 | " \"width\": 720,\n" +
43 | " \"height\": 1080,\n" +
44 | " \"format\": \"jpeg\",\n" +
45 | " \"size\": 704200,\n" +
46 | " \"url\": \"https://picsum.photos/id/199/720/1080\"\n" +
47 | "},\n" +
48 | "{\n" +
49 | " \"width\": 1080,\n" +
50 | " \"height\": 1080,\n" +
51 | " \"format\": \"jpeg\",\n" +
52 | " \"size\": 30155,\n" +
53 | " \"url\": \"https://picsum.photos/id/191/1080/1080\"\n" +
54 | "}\n" +
55 | "]"
--------------------------------------------------------------------------------
/app/src/main/java/com/example/dynamicviewpager/ScrollingActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import com.google.gson.Gson
6 | import kotlinx.android.synthetic.main.activity_review_detail_header.*
7 | import kotlinx.android.synthetic.main.activity_scrolling.*
8 |
9 |
10 | class ScrollingActivity : AppCompatActivity() {
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_scrolling)
15 | setSupportActionBar(toolbar)
16 | // fab.setOnClickListener { view ->
17 | // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
18 | // .setAction("Action", null).show()
19 | // }
20 |
21 | // 布局里使用 fitSystemWindows 导致有一个状态栏高度的 padding 存在
22 | // 暂时没找到好的解决方案。有的话请告诉我
23 | // https://stackoverflow.com/questions/48137666/viewgroup-inside-collapsingtoolbarlayout-show-extra-bottom-padding-when-set-fits
24 |
25 | init()
26 | }
27 |
28 | private fun init() {
29 | val images = Gson().fromJson(JSON_DATA, Array::class.java).asList()
30 | viewPager.adapter = TransformViewPagerAdapter(supportFragmentManager, images)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/dynamicviewpager/SimpleImageFragment.kt:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager
2 |
3 |
4 | import android.os.Bundle
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import androidx.fragment.app.Fragment
9 | import com.bumptech.glide.Glide
10 | import kotlinx.android.synthetic.main.fragment_simple_image.*
11 |
12 | /**
13 | * A simple [Fragment] subclass.
14 | */
15 | class SimpleImageFragment : Fragment() {
16 |
17 | companion object {
18 | const val ARG_IMAGE = "image"
19 | fun newInstance(image: Image): SimpleImageFragment {
20 | return SimpleImageFragment().apply {
21 | arguments = Bundle().apply {
22 | putSerializable(ARG_IMAGE, image)
23 | }
24 | }
25 | }
26 | }
27 |
28 | override fun onCreateView(
29 | inflater: LayoutInflater, container: ViewGroup?,
30 | savedInstanceState: Bundle?
31 | ): View? {
32 | return inflater.inflate(R.layout.fragment_simple_image, container, false)
33 | }
34 |
35 |
36 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
37 | super.onViewCreated(view, savedInstanceState)
38 | val image = arguments!!.getSerializable(ARG_IMAGE) as Image
39 | Glide.with(this).load(image.url).fitCenter().into(imageView)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/dynamicviewpager/TransformViewPagerAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager
2 |
3 | import android.view.ViewGroup
4 | import androidx.fragment.app.Fragment
5 | import androidx.fragment.app.FragmentManager
6 | import androidx.fragment.app.FragmentPagerAdapter
7 | import com.danteandroid.transformviewpager.Transformable
8 | import com.danteandroid.transformviewpager.TransformableAdapter
9 |
10 | /**
11 | * @author Dante
12 | * 2019-11-11
13 | */
14 |
15 | class TransformViewPagerAdapter(fragmentManager: FragmentManager, val images: List) :
16 | FragmentPagerAdapter(fragmentManager), TransformableAdapter {
17 |
18 | override fun getTransformableItems(): List {
19 | return images
20 | }
21 |
22 | private val fragments: ArrayList = arrayListOf()
23 |
24 | init {
25 | for (image in images) {
26 | fragments.add(SimpleImageFragment.newInstance(image))
27 | }
28 | }
29 |
30 | override fun getItem(index: Int): Fragment = fragments[index]
31 |
32 | override fun getCount(): Int = images.size
33 |
34 | override fun setPrimaryItem(container: ViewGroup, position: Int, `object`: Any) {
35 | super.setPrimaryItem(container, position, `object`)
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
48 |
49 |
53 |
54 |
61 |
62 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_review_detail_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scrolling.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
26 |
27 |
28 |
29 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_scrolling.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_simple_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_scrolling.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 180dp
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DynamicViewPager
3 | ScrollingActivity
4 |
5 | "Material is the metaphor.\n\n"
6 |
7 | "A material metaphor is the unifying theory of a rationalized space and a system of motion."
8 | "The material is grounded in tactile reality, inspired by the study of paper and ink, yet "
9 | "technologically advanced and open to imagination and magic.\n"
10 | "Surfaces and edges of the material provide visual cues that are grounded in reality. The "
11 | "use of familiar tactile attributes helps users quickly understand affordances. Yet the "
12 | "flexibility of the material creates new affordances that supercede those in the physical "
13 | "world, without breaking the rules of physics.\n"
14 | "The fundamentals of light, surface, and movement are key to conveying how objects move, "
15 | "interact, and exist in space and in relation to each other. Realistic lighting shows "
16 | "seams, divides space, and indicates moving parts.\n\n"
17 |
18 | "Bold, graphic, intentional.\n\n"
19 |
20 | "The foundational elements of print based design typography, grids, space, scale, color, "
21 | "and use of imagery guide visual treatments. These elements do far more than please the "
22 | "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge "
23 | "imagery, large scale typography, and intentional white space create a bold and graphic "
24 | "interface that immerse the user in the experience.\n"
25 | "An emphasis on user actions makes core functionality immediately apparent and provides "
26 | "waypoints for the user.\n\n"
27 |
28 | "Motion provides meaning.\n\n"
29 |
30 | "Motion respects and reinforces the user as the prime mover. Primary user actions are "
31 | "inflection points that initiate motion, transforming the whole design.\n"
32 | "All action takes place in a single environment. Objects are presented to the user without "
33 | "breaking the continuity of experience even as they transform and reorganize.\n"
34 | "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. "
35 | "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n"
36 |
37 | "3D world.\n\n"
38 |
39 | "The material environment is a 3D space, which means all objects have x, y, and z "
40 | "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the "
41 | "positive z-axis extending towards the viewer. Every sheet of material occupies a single "
42 | "position along the z-axis and has a standard 1dp thickness.\n"
43 | "On the web, the z-axis is used for layering and not for perspective. The 3D world is "
44 | "emulated by manipulating the y-axis.\n\n"
45 |
46 | "Light and shadow.\n\n"
47 |
48 | "Within the material environment, virtual lights illuminate the scene. Key lights create "
49 | "directional shadows, while ambient light creates soft shadows from all angles.\n"
50 | "Shadows in the material environment are cast by these two light sources. In Android "
51 | "development, shadows occur when light sources are blocked by sheets of material at "
52 | "various positions along the z-axis. On the web, shadows are depicted by manipulating the "
53 | "y-axis only. The following example shows the card with a height of 6dp.\n\n"
54 |
55 | "Resting elevation.\n\n"
56 |
57 | "All material objects, regardless of size, have a resting elevation, or default elevation "
58 | "that does not change. If an object changes elevation, it should return to its resting "
59 | "elevation as soon as possible.\n\n"
60 |
61 | "Component elevations.\n\n"
62 |
63 | "The resting elevation for a component type is consistent across apps (e.g., FAB elevation "
64 | "does not vary from 6dp in one app to 16dp in another app).\n"
65 | "Components may have different resting elevations across platforms, depending on the depth "
66 | "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n"
67 |
68 | "Responsive elevation and dynamic elevation offsets.\n\n"
69 |
70 | "Some component types have responsive elevation, meaning they change elevation in response "
71 | "to user input (e.g., normal, focused, and pressed) or system events. These elevation "
72 | "changes are consistently implemented using dynamic elevation offsets.\n"
73 | "Dynamic elevation offsets are the goal elevation that a component moves towards, relative "
74 | "to the component’s resting state. They ensure that elevation changes are consistent "
75 | "across actions and component types. For example, all components that lift on press have "
76 | "the same elevation change relative to their resting elevation.\n"
77 | "Once the input event is completed or cancelled, the component will return to its resting "
78 | "elevation.\n\n"
79 |
80 | "Avoiding elevation interference.\n\n"
81 |
82 | "Components with responsive elevations may encounter other components as they move between "
83 | "their resting elevations and dynamic elevation offsets. Because material cannot pass "
84 | "through other material, components avoid interfering with one another any number of ways, "
85 | "whether on a per component basis or using the entire app layout.\n"
86 | "On a component level, components can move or be removed before they cause interference. "
87 | "For example, a floating action button (FAB) can disappear or move off screen before a "
88 | "user picks up a card, or it can move if a snackbar appears.\n"
89 | "On the layout level, design your app layout to minimize opportunities for interference. "
90 | "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere "
91 | "when a user tries to pick up one of cards.\n\n"
92 |
93 | Settings
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/dynamicviewpager/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.dynamicviewpager
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.50'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.5.2'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 |
16 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | jcenter()
24 |
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/demo.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | #android.useAndroidX=true
18 | ## Automatically convert third-party libraries to use AndroidX
19 | #android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 | android.useAndroidX=true
23 | android.enableJetifier=true
24 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 07 15:00:15 CST 2019
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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':transformviewpager'
2 | rootProject.name='DynamicViewPager'
3 |
--------------------------------------------------------------------------------
/transformviewpager/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/transformviewpager/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | apply plugin: 'com.github.dcendents.android-maven'
6 |
7 | group='com.github.DanteAndroid'
8 |
9 | android {
10 | compileSdkVersion 29
11 | buildToolsVersion "29.0.2"
12 |
13 |
14 | defaultConfig {
15 | minSdkVersion 19
16 | targetSdkVersion 29
17 | versionCode 1
18 | versionName "1.0"
19 |
20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21 | consumerProguardFiles 'consumer-rules.pro'
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 |
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(dir: 'libs', include: ['*.jar'])
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
36 | implementation 'androidx.appcompat:appcompat:1.1.0'
37 | implementation 'androidx.core:core-ktx:1.1.0'
38 | testImplementation 'junit:junit:4.12'
39 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
40 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
41 | }
42 |
--------------------------------------------------------------------------------
/transformviewpager/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DanteAndroid/TransformViewPager/011dadb2c83104b9fe5d047cf37e117c637647e9/transformviewpager/consumer-rules.pro
--------------------------------------------------------------------------------
/transformviewpager/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/transformviewpager/src/androidTest/java/com/danteandroid/transformviewpager/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.danteandroid.transformviewpager
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.danteandroid.transformviewpager.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/transformviewpager/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/transformviewpager/src/main/java/com/danteandroid/transformviewpager/TransformViewPager.kt:
--------------------------------------------------------------------------------
1 | package com.danteandroid.transformviewpager
2 |
3 | import android.content.Context
4 | import android.util.AttributeSet
5 | import android.view.ViewGroup
6 | import androidx.viewpager.widget.PagerAdapter
7 | import androidx.viewpager.widget.ViewPager
8 |
9 | /**
10 | * @author Dante
11 | * 2019-11-06
12 | */
13 | class TransformViewPager : ViewPager {
14 |
15 | constructor(context: Context) : super(context)
16 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
17 |
18 | override fun setAdapter(adapter: PagerAdapter?) {
19 | super.setAdapter(adapter)
20 | check(adapter is TransformableAdapter) { "You should set adapter that implements `TransformableAdapter`" }
21 | // 初始高度为第一张图片的实际显示高度
22 | layoutParams.height = getRealHeight(0)
23 |
24 | addOnPageChangeListener(object : OnPageChangeListener {
25 | private var lastOffset = 0
26 | override fun onPageScrollStateChanged(position: Int) {
27 |
28 | }
29 |
30 | override fun onPageScrolled(
31 | position: Int,
32 | positionOffset: Float,
33 | positionOffsetPixels: Int
34 | ) {
35 | val scrollToLeft = positionOffsetPixels - lastOffset < 0
36 | lastOffset = positionOffsetPixels
37 | transform(position, positionOffset, scrollToLeft)
38 | }
39 |
40 | override fun onPageSelected(position: Int) {
41 |
42 | }
43 | })
44 | }
45 |
46 | // 注意,我要变形了!
47 | private fun transform(position: Int, positionOffset: Float, isLeft: Boolean) {
48 | if (positionOffset == 0f || positionOffset == 1f) return
49 | // 如果向左划,position 为左边那个,故需要 +1
50 | val currentPosition = if (isLeft) position + 1 else position
51 | // 计算目标高度与当前高度的差值
52 | // 然后乘以滑动offset(在屏幕宽度中)的比例
53 | val diff = (getDestHeight(currentPosition, isLeft) -
54 | getRealHeight(currentPosition)) * if (isLeft) 1 - positionOffset else positionOffset
55 |
56 | layoutParams.height = getRealHeight(currentPosition) + diff.toInt()
57 | requestLayout()
58 |
59 | println(
60 | "onScrollChanged position $currentPosition, getRealHeight ${
61 | getRealHeight(
62 | position
63 | )
64 | }, " + "diffHeight $diff, layoutParams.height ${layoutParams.height}"
65 | )
66 | }
67 |
68 | private fun getDestHeight(position: Int, scrollToLeft: Boolean): Int {
69 | val nextImagePosition = if (scrollToLeft && position >= 1) {
70 | position - 1
71 | } else position + 1
72 |
73 | return getRealHeight(nextImagePosition)
74 | }
75 |
76 | private fun getRealHeight(position: Int): Int {
77 | val adapter = adapter as TransformableAdapter
78 | val image = adapter.getTransformableItems()[position]
79 | val width = getRealWidth(position)
80 | return (image.getOrignalHeight() / image.getOriginalWidth() * width).toInt()
81 | }
82 |
83 | private fun getRealWidth(position: Int): Int {
84 | val adapter = adapter as TransformableAdapter
85 | val image = adapter.getTransformableItems()[position]
86 | return when {
87 | layoutParams.width == ViewGroup.LayoutParams.WRAP_CONTENT -> {
88 | image.getOriginalWidth().toInt()
89 | }
90 | layoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT -> {
91 | UiUtils.getScreenWidth(context)
92 | }
93 | else -> layoutParams.width
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/transformviewpager/src/main/java/com/danteandroid/transformviewpager/Transformable.kt:
--------------------------------------------------------------------------------
1 | package com.danteandroid.transformviewpager
2 |
3 | /**
4 | * @author Dante
5 | * 2019-11-11
6 | */
7 | interface Transformable {
8 |
9 | fun getOriginalWidth(): Float
10 | fun getOrignalHeight(): Float
11 |
12 | }
13 |
14 | interface TransformableAdapter {
15 |
16 | fun getTransformableItems(): List
17 |
18 | }
--------------------------------------------------------------------------------
/transformviewpager/src/main/java/com/danteandroid/transformviewpager/UiUtils.kt:
--------------------------------------------------------------------------------
1 | package com.danteandroid.transformviewpager
2 |
3 | import android.content.Context
4 |
5 | /**
6 | * @author Dante
7 | * 2019-11-07
8 | */
9 | object UiUtils {
10 |
11 | fun getScreenWidth(context: Context): Int {
12 | return context.getResources().getDisplayMetrics().widthPixels
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/transformviewpager/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TransformViewPager
3 |
4 |
--------------------------------------------------------------------------------
/transformviewpager/src/test/java/com/danteandroid/transformviewpager/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.danteandroid.transformviewpager
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------