├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── imxie │ │ └── exvpbs │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── imxie │ │ │ └── exvpbs │ │ │ └── demo │ │ │ ├── MainActivity.kt │ │ │ ├── SimpleAdapter.kt │ │ │ ├── SimpleListFragment.kt │ │ │ ├── ViewPager2Activity.kt │ │ │ └── ViewPagerActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_viewpager.xml │ │ ├── activity_viewpager2.xml │ │ ├── fragment_tab.xml │ │ └── list_item_tab.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 │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── imxie │ └── exvpbs │ └── ExampleUnitTest.kt ├── build.gradle ├── exvpbs ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── imxie │ └── exvpbs │ ├── BottomSheetVP2Helper.kt │ ├── BottomSheetVPHelper.kt │ └── ViewPagerBottomSheetBehavior.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pic └── demo.gif └── settings.gradle /.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 | # ExViewPagerBottomSheet 2 | 3 | [![](https://jitpack.io/v/xcc3641/ExViewPagerBottomSheet.svg)](https://jitpack.io/#xcc3641/ExViewPagerBottomSheet) 4 | 5 | 🌟 Help to use ViewPager/ViewPager2 in Bottom Sheet or Bottom Sheet Dialog! 6 | 7 | # Demo 8 | 9 | ![](pic/demo.gif) 10 | 11 | # Usage 12 | 13 | Add it in your root `build.gradle` at the end of repositories: 14 | 15 | ``` 16 | allprojects { 17 | repositories { 18 | ... 19 | maven { url 'https://jitpack.io' } 20 | } 21 | } 22 | ``` 23 | 24 | Add the dependency 25 | 26 | ``` 27 | dependencies { 28 | implementation 'com.github.xcc3641:ExViewPagerBottomSheet:' 29 | } 30 | ``` 31 | 32 | Use `ViewPagerBottomSheetBehavior` for your bottom sheet view: 33 | 34 | ``` 35 | app:layout_behavior="com.imxie.exvpbs.ViewPagerBottomSheetBehavior" 36 | ``` 37 | 38 | Setup ViewPager/ViewPager2: 39 | 40 | ``` 41 | // ViewPager 42 | BottomSheetVPHelper.setupViewPager(vp) 43 | 44 | // ViewPager2 45 | BottomSheetVP2Helper.setupViewPager(vp) 46 | ``` 47 | 48 | # Thanks 49 | 50 | - [ViewPagerBottomSheet](https://github.com/laenger/ViewPagerBottomSheet) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 29 7 | buildToolsVersion "29.0.3" 8 | 9 | defaultConfig { 10 | applicationId "com.imxie.exvpbs" 11 | minSdkVersion 19 12 | targetSdkVersion 29 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | } 31 | 32 | dependencies { 33 | implementation fileTree(dir: 'libs', include: ['*.jar']) 34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 35 | implementation 'androidx.appcompat:appcompat:1.1.0' 36 | implementation 'androidx.core:core-ktx:1.2.0' 37 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 38 | implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0" 39 | implementation "androidx.recyclerview:recyclerview:1.1.0" 40 | implementation "androidx.viewpager2:viewpager2:1.0.0" 41 | testImplementation 'junit:junit:4.13' 42 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 43 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 44 | implementation project(':exvpbs') 45 | } 46 | -------------------------------------------------------------------------------- /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/imxie/exvpbs/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.imxie.exvpbs 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.imxie.exvpbs", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/imxie/exvpbs/demo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.imxie.exvpbs.demo 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import kotlinx.android.synthetic.main.activity_main.* 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | 14 | btnVP.setOnClickListener { 15 | startActivity(Intent(this, ViewPagerActivity::class.java)) 16 | } 17 | btnVP2.setOnClickListener { 18 | startActivity(Intent(this, ViewPager2Activity::class.java)) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/imxie/exvpbs/demo/SimpleAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.imxie.exvpbs.demo 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | import kotlinx.android.synthetic.main.list_item_tab.view.* 7 | 8 | 9 | class SimpleAdapter : RecyclerView.Adapter() { 10 | 11 | private val data = arrayListOf() 12 | 13 | init { 14 | data.addAll(1 until 20) 15 | } 16 | 17 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder { 18 | return SimpleViewHolder(parent) 19 | } 20 | 21 | override fun getItemCount(): Int { 22 | return data.size 23 | } 24 | 25 | override fun onBindViewHolder(holder: SimpleViewHolder, position: Int) { 26 | holder.itemView.tvContent.text = "这是第${data[position]}个" 27 | } 28 | } 29 | 30 | 31 | class SimpleViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder( 32 | LayoutInflater.from(parent.context).inflate(R.layout.list_item_tab, parent, false) 33 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/imxie/exvpbs/demo/SimpleListFragment.kt: -------------------------------------------------------------------------------- 1 | package com.imxie.exvpbs.demo 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.core.os.bundleOf 6 | import androidx.fragment.app.Fragment 7 | import kotlinx.android.synthetic.main.fragment_tab.* 8 | 9 | 10 | class SimpleListFragment : Fragment(R.layout.fragment_tab) { 11 | 12 | private var indexStr = "" 13 | override fun setArguments(args: Bundle?) { 14 | indexStr = args?.getString(DATA) ?: "" 15 | } 16 | 17 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 18 | super.onViewCreated(view, savedInstanceState) 19 | tvContent.text = indexStr 20 | rv.adapter = SimpleAdapter() 21 | } 22 | 23 | companion object { 24 | 25 | const val DATA = "data" 26 | 27 | fun new(index: Int): SimpleListFragment { 28 | return SimpleListFragment().apply { arguments = bundleOf(DATA to index.toString()) } 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/imxie/exvpbs/demo/ViewPager2Activity.kt: -------------------------------------------------------------------------------- 1 | package com.imxie.exvpbs.demo 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.fragment.app.Fragment 6 | import androidx.viewpager2.adapter.FragmentStateAdapter 7 | import com.imxie.exvpbs.BottomSheetVP2Helper 8 | import kotlinx.android.synthetic.main.activity_viewpager2.vp 9 | 10 | 11 | class ViewPager2Activity : AppCompatActivity() { 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_viewpager2) 16 | (0 until 10).map { SimpleListFragment.new(it) }.also { list -> 17 | vp.adapter = object : FragmentStateAdapter(this) { 18 | override fun getItemCount(): Int { 19 | return list.size 20 | } 21 | 22 | override fun createFragment(position: Int): Fragment { 23 | return list[position] 24 | } 25 | } 26 | } 27 | 28 | BottomSheetVP2Helper.setupViewPager(vp) 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /app/src/main/java/com/imxie/exvpbs/demo/ViewPagerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.imxie.exvpbs.demo 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.fragment.app.Fragment 6 | import androidx.fragment.app.FragmentStatePagerAdapter 7 | import com.imxie.exvpbs.BottomSheetVPHelper 8 | import kotlinx.android.synthetic.main.activity_viewpager.* 9 | 10 | 11 | class ViewPagerActivity : AppCompatActivity() { 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_viewpager) 16 | 17 | (0 until 10).map { SimpleListFragment.new(it) }.also { list -> 18 | vp.adapter = object : FragmentStatePagerAdapter( 19 | supportFragmentManager, 20 | BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT 21 | ) { 22 | override fun getItem(position: Int): Fragment { 23 | return list[position] 24 | } 25 | 26 | override fun getCount(): Int { 27 | return list.size 28 | } 29 | 30 | } 31 | } 32 | 33 | BottomSheetVPHelper.setupViewPager(vp) 34 | } 35 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /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 | 2 | 10 | 11 |