├── .gitignore ├── .idea ├── .gitignore ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── demo │ │ └── simple │ │ └── layoutmanager │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── demo │ │ │ └── simple │ │ │ └── layoutmanager │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item_text.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-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── demo │ └── simple │ └── layoutmanager │ └── ExampleUnitTest.kt ├── build.gradle ├── files └── gif_max_line_layout_manager.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── me │ └── simple │ └── layoutmanager │ ├── Helper.kt │ ├── MaxLineGridLayoutManager.kt │ ├── MaxLineLinearLayoutManager.kt │ └── MaxLineStaggeredGridLayoutManager.kt └── 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 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 119 | 120 | 122 | 123 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MaxLineLayoutManager 2 | 3 | 当itemCount超过设定数量就固定高度的LayoutManager,类似maxHeight 4 | 5 | ![](files/gif_max_line_layout_manager.gif) 6 | 7 | ## 导入依赖 8 | 9 | ```groovy 10 | maven { url 'https://www.jitpack.io' } 11 | ``` 12 | 13 | ```groovy 14 | implementation 'com.github.simplepeng:MaxLineLayoutManager:v1.0.0' 15 | ``` 16 | 17 | ## 使用 18 | 19 | ```kotlin 20 | recyclerView.layoutManager = MaxLineLinearLayoutManager(this, maxLine = 3) 21 | recyclerView.adapter = .... 22 | ``` 23 | 24 | ## 可用LayoutManager 25 | 26 | * MaxLineLinearLayoutManager 27 | * MaxLineGridLayoutManager 28 | * MaxLineStaggeredGridLayoutManager 29 | 30 | ## 版本迭代 31 | 32 | * v1.0.0:首次上传 33 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-android-extensions' 5 | } 6 | 7 | android { 8 | compileSdkVersion 30 9 | buildToolsVersion "30.0.2" 10 | 11 | defaultConfig { 12 | applicationId "demo.simple.layoutmanager" 13 | minSdkVersion 16 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_8 29 | targetCompatibility JavaVersion.VERSION_1_8 30 | } 31 | kotlinOptions { 32 | jvmTarget = '1.8' 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 38 | implementation 'androidx.core:core-ktx:1.3.2' 39 | implementation 'androidx.appcompat:appcompat:1.2.0' 40 | implementation 'com.google.android.material:material:1.2.1' 41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.3' 42 | implementation project(path: ':library') 43 | testImplementation 'junit:junit:4.+' 44 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 46 | 47 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/androidTest/java/demo/simple/layoutmanager/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package demo.simple.layoutmanager 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("demo.simple.layoutmanager", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/demo/simple/layoutmanager/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package demo.simple.layoutmanager 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.TextView 9 | import androidx.recyclerview.widget.GridLayoutManager 10 | import androidx.recyclerview.widget.LinearLayoutManager 11 | import androidx.recyclerview.widget.RecyclerView 12 | import androidx.recyclerview.widget.StaggeredGridLayoutManager 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | import me.simple.layoutmanager.MaxLineGridLayoutManager 15 | import me.simple.layoutmanager.MaxLineLinearLayoutManager 16 | import me.simple.layoutmanager.MaxLineStaggeredGridLayoutManager 17 | 18 | class MainActivity : AppCompatActivity() { 19 | 20 | private val mItems = mutableListOf() 21 | private val mAdapter = Adapter() 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setContentView(R.layout.activity_main) 26 | 27 | mItems.add(1) 28 | 29 | // recyclerView.layoutManager = LinearLayoutManager(this) 30 | recyclerView.layoutManager = MaxLineLinearLayoutManager(this, maxLine = 3) 31 | // recyclerView.layoutManager = 32 | // MaxLineLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false, 3) 33 | 34 | // recyclerView.layoutManager = GridLayoutManager(this,2) 35 | // recyclerView.layoutManager = 36 | // MaxLineGridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false, 3) 37 | 38 | // recyclerView.layoutManager = 39 | // StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.HORIZONTAL) 40 | // recyclerView.layoutManager = 41 | // MaxLineStaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL, 3) 42 | 43 | recyclerView.adapter = mAdapter 44 | } 45 | 46 | fun addItem(view: View) { 47 | mItems.add(1) 48 | // mAdapter.notifyDataSetChanged() 49 | mAdapter.notifyItemInserted(mItems.lastIndex) 50 | 51 | recyclerView.postDelayed({ 52 | recyclerView.smoothScrollToPosition(mItems.lastIndex) 53 | }, 300) 54 | } 55 | 56 | fun delItem(view: View) { 57 | if (mItems.isEmpty()) return 58 | val index = mItems.lastIndex 59 | mItems.removeAt(index) 60 | mAdapter.notifyItemRemoved(index) 61 | } 62 | 63 | inner class Adapter : RecyclerView.Adapter() { 64 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { 65 | return Holder( 66 | LayoutInflater.from(parent.context).inflate(R.layout.item_text, parent, false) 67 | ) 68 | } 69 | 70 | override fun getItemCount(): Int { 71 | return mItems.size 72 | } 73 | 74 | override fun onBindViewHolder(holder: Holder, position: Int) { 75 | holder.tvItem.text = position.toString() 76 | } 77 | 78 | } 79 | 80 | class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) { 81 | val tvItem = itemView.findViewById(R.id.tvItem) 82 | } 83 | } -------------------------------------------------------------------------------- /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 | 8 | 9 | 19 | 20 | 21 |