├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── btn_toggle.xml │ │ │ │ ├── ic_arrow_up.xml │ │ │ │ ├── ic_more.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── item_toggle.xml │ │ │ │ └── item_movie_turn.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── xbm │ │ │ └── expandgridlist │ │ │ ├── bean │ │ │ └── MovieBean.java │ │ │ ├── decoration │ │ │ └── HeaderGridSpacingItemDecoration.java │ │ │ ├── adapter │ │ │ ├── MovieRVAdapter.java │ │ │ ├── BaseRVAdapter.java │ │ │ └── ExpandAdapter.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── xbm │ │ │ └── expandgridlist │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── xbm │ │ └── expandgridlist │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gif └── 1.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── caches │ └── build_file_checksums.ser ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── misc.xml └── codeStyles │ └── Project.xml ├── README.md ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /gif/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/gif/1.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ExpandGridList 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenmowl/ExpandGridList/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExpandGridList 2 | 可伸缩剧集列表 3 | 4 | Expand Grid RecyclerView 5 | 6 | 支持自定义伸缩值 7 | 8 | 9 | ![](https://github.com/chenmowl/ExpandGridList/blob/master/gif/1.gif) -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed May 02 16:47:08 CST 2018 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-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_toggle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_up.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/xbm/expandgridlist/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_more.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /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/xbm/expandgridlist/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.xbm.expandgridlist", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/xbm/expandgridlist/bean/MovieBean.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist.bean; 2 | 3 | /** 4 | * Created by xbm on 2018/3/7. 5 | */ 6 | public class MovieBean { 7 | String name; 8 | String turn; 9 | private boolean isToggle; 10 | 11 | public MovieBean(String name, String turn) { 12 | this.name = name; 13 | this.turn = turn; 14 | } 15 | 16 | public MovieBean(String name, String turn, boolean isToggle) { 17 | this.name = name; 18 | this.turn = turn; 19 | this.isToggle = isToggle; 20 | } 21 | 22 | public boolean isToggle() { 23 | return isToggle; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getTurn() { 35 | return turn; 36 | } 37 | 38 | public void setTurn(String turn) { 39 | this.turn = turn; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.xbm.expandgridlist" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation "com.android.support:recyclerview-v7:26.1.0" 25 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 29 | } 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 25 | 26 | 35 | 36 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /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/layout/item_toggle.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 25 | 26 | 36 | 37 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_movie_turn.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 18 | 19 | 26 | 27 | 38 | 39 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/xbm/expandgridlist/decoration/HeaderGridSpacingItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist.decoration; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | /** 8 | * 带header三列gridview加分割线 9 | */ 10 | public class HeaderGridSpacingItemDecoration extends RecyclerView.ItemDecoration { 11 | 12 | private int spanCount; 13 | private int spacing; 14 | private int headerCount;//列表头个数 15 | private boolean includeEdge;//是否边界加分割线 16 | 17 | public HeaderGridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) { 18 | this.spanCount = spanCount; 19 | this.spacing = spacing; 20 | this.includeEdge = includeEdge; 21 | headerCount = 1; 22 | } 23 | 24 | public HeaderGridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge, int headerCount) { 25 | this.spanCount = spanCount; 26 | this.spacing = spacing; 27 | this.includeEdge = includeEdge; 28 | this.headerCount = headerCount; 29 | } 30 | 31 | @Override 32 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 33 | int position = parent.getChildAdapterPosition(view); // item position 34 | if (position >= headerCount) { 35 | int column = (position - headerCount) % spanCount; // item column 36 | 37 | if (includeEdge) { 38 | outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing) 39 | outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing) 40 | 41 | if (position < spanCount) { // top edge 42 | // outRect.top = spacing; 43 | } 44 | outRect.bottom = spacing; // item bottom 45 | } else { 46 | outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing) 47 | outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing) 48 | if (position >= spanCount) { 49 | // outRect.top = spacing; // item top 50 | } 51 | } 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/java/com/xbm/expandgridlist/adapter/MovieRVAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist.adapter; 2 | 3 | import android.view.View; 4 | import android.widget.TextView; 5 | 6 | import com.xbm.expandgridlist.R; 7 | import com.xbm.expandgridlist.bean.MovieBean; 8 | 9 | 10 | /** 11 | * Created by xbm on 2018/3/8. 12 | */ 13 | 14 | public class MovieRVAdapter extends BaseRVAdapter { 15 | 16 | int criticalCount;//伸缩临界值 17 | 18 | boolean isHide; 19 | 20 | private MovieBean bean; 21 | 22 | public MovieRVAdapter(int criticalCount) { 23 | super(R.layout.item_movie_turn); 24 | isHide = true; 25 | this.criticalCount = criticalCount; 26 | bean = new MovieBean("", "", true); 27 | } 28 | 29 | @Override 30 | public void onBindViewHolder(MBaseViewHolder holder, int position) { 31 | super.onBindViewHolder(holder, position); 32 | TextView tvContent = holder.getView(R.id.tv_content); 33 | View toggle = holder.getView(R.id.toggle); 34 | MovieBean bean = mData.get(position); 35 | if (bean.isToggle()) { 36 | tvContent.setText(""); 37 | toggle.setVisibility(View.VISIBLE); 38 | toggle.setSelected(!isHide); 39 | } else { 40 | toggle.setVisibility(View.GONE); 41 | tvContent.setText(bean.getTurn()); 42 | } 43 | } 44 | 45 | @Override 46 | public int getItemCount() { 47 | int max = criticalCount; 48 | int size = mData.size();//真实数据的数量 49 | size = mData.contains(bean) ? size - 1 : size;//去除非数据项 50 | if (size > max) { 51 | //这是根据状态值隐藏 52 | if (isHide) { 53 | if (!mData.contains(bean)) { 54 | mData.add(max - 1, bean); 55 | } else { 56 | int i = mData.indexOf(bean); 57 | if (i != max - 1) { 58 | mData.remove(bean); 59 | mData.add(max - 1, bean); 60 | } 61 | } 62 | return max; 63 | } else { 64 | if (mData.contains(bean)) { 65 | int i = mData.indexOf(bean); 66 | if (i != size) { 67 | mData.remove(bean); 68 | mData.add(bean); 69 | } 70 | } else { 71 | mData.add(bean); 72 | } 73 | return mData.size(); 74 | } 75 | } else { 76 | if (mData.contains(bean)) { 77 | mData.remove(bean); 78 | } 79 | return mData.size(); 80 | } 81 | } 82 | 83 | /** 84 | * 切换剧集伸缩的方法 85 | */ 86 | public void toggle() { 87 | isHide = !isHide; 88 | notifyDataSetChanged(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/xbm/expandgridlist/adapter/BaseRVAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist.adapter; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.SparseArray; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collection; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by xbm on 2018/3/8. 16 | */ 17 | public abstract class BaseRVAdapter extends RecyclerView.Adapter { 18 | 19 | @NonNull 20 | public List mData; 21 | @NonNull 22 | private int layoutId; 23 | 24 | public BaseRVAdapter(@NonNull int layoutId) { 25 | this.layoutId = layoutId; 26 | mData = new ArrayList<>(); 27 | } 28 | 29 | public BaseRVAdapter(@NonNull List mData, @NonNull int layoutId) { 30 | this.mData = mData; 31 | this.layoutId = layoutId; 32 | } 33 | 34 | @Override 35 | public MBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 36 | View inflate = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false); 37 | return MBaseViewHolder.get(inflate); 38 | } 39 | 40 | @Override 41 | public void onBindViewHolder(MBaseViewHolder holder, int position) { 42 | holder.itemView.setOnClickListener(new RVClickListener(position)); 43 | } 44 | 45 | @Override 46 | public int getItemCount() { 47 | return mData.size(); 48 | } 49 | 50 | public void replaceData(@NonNull Collection data) { 51 | // 不是同一个引用才清空列表 52 | if (data != mData) { 53 | mData.clear(); 54 | mData.addAll(data); 55 | } 56 | notifyDataSetChanged(); 57 | } 58 | 59 | static class MBaseViewHolder extends RecyclerView.ViewHolder { 60 | 61 | private SparseArray mViews; 62 | 63 | public MBaseViewHolder(View itemView) { 64 | super(itemView); 65 | mViews = new SparseArray(); 66 | } 67 | 68 | public static MBaseViewHolder get(View itemView) { 69 | return new MBaseViewHolder(itemView); 70 | } 71 | 72 | public T getView(int viewId) { 73 | View view = mViews.get(viewId); 74 | if (view == null) { 75 | view = itemView.findViewById(viewId); 76 | mViews.put(viewId, view); 77 | } 78 | return (T) view; 79 | } 80 | } 81 | 82 | private ItemClickListener itemClickListener;//点击事件的监听 83 | 84 | public void setItemClickListener(ItemClickListener itemClickListener) { 85 | this.itemClickListener = itemClickListener; 86 | } 87 | 88 | public ItemClickListener getItemClickListener() { 89 | return itemClickListener; 90 | } 91 | 92 | public interface ItemClickListener { 93 | void itemClick(BaseRVAdapter adapter, View view, int position); 94 | } 95 | 96 | class RVClickListener implements View.OnClickListener { 97 | 98 | int position; 99 | 100 | public RVClickListener(int position) { 101 | this.position = position; 102 | } 103 | 104 | @Override 105 | public void onClick(View v) { 106 | if (itemClickListener != null) { 107 | itemClickListener.itemClick(BaseRVAdapter.this, v, position); 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/com/xbm/expandgridlist/adapter/ExpandAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist.adapter; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.widget.TextView; 6 | 7 | import com.xbm.expandgridlist.R; 8 | 9 | /** 10 | * 第二种方式的伸展布局适配器,相比于第一种不依赖javabean 11 | */ 12 | public class ExpandAdapter extends BaseRVAdapter implements View.OnClickListener { 13 | 14 | private static final int TYPE_TOGGLE = 1; 15 | 16 | private View expandView;//回缩按钮 17 | 18 | private int criticalCount;//伸缩临界值 19 | 20 | private boolean hide;//是否处于回缩状态 21 | 22 | public ExpandAdapter() { 23 | super(R.layout.item_movie_turn); 24 | criticalCount = 10; 25 | } 26 | 27 | public ExpandAdapter(int criticalCount) { 28 | super(R.layout.item_movie_turn); 29 | this.criticalCount = criticalCount; 30 | hide = true; 31 | } 32 | 33 | /** 34 | * 设置toggle 控件 35 | * 36 | * @param expandView 37 | */ 38 | public void setExpandView(View expandView) { 39 | this.expandView = expandView; 40 | } 41 | 42 | public void setCriticalCount(int criticalCount) { 43 | this.criticalCount = criticalCount; 44 | } 45 | 46 | @Override 47 | public MBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 48 | if (viewType == TYPE_TOGGLE) { 49 | if (expandView == null) { 50 | throw new IllegalArgumentException("ExpandAdapter中 expandView 不能为null"); 51 | } else { 52 | return MBaseViewHolder.get(expandView); 53 | } 54 | } 55 | return super.onCreateViewHolder(parent, viewType); 56 | } 57 | 58 | @Override 59 | public void onBindViewHolder(MBaseViewHolder holder, int position) { 60 | int itemViewType = getItemViewType(position); 61 | if (itemViewType == TYPE_TOGGLE) { 62 | // TODO: 2018/5/2 这里处理toggle点击事件 63 | if (expandView != null) { 64 | expandView.setOnClickListener(this); 65 | } 66 | } else { 67 | super.onBindViewHolder(holder, position); 68 | TextView tvContent = holder.getView(R.id.tv_content); 69 | tvContent.setText(String.valueOf(position)); 70 | } 71 | } 72 | 73 | @Override 74 | public int getItemCount() { 75 | int dataLength = mData.size(); 76 | if (dataLength >= criticalCount) { 77 | //超过临界值,添加footer 78 | if (hide) { 79 | return criticalCount; 80 | } else { 81 | return dataLength + 1; 82 | } 83 | } 84 | return super.getItemCount(); 85 | } 86 | 87 | @Override 88 | public int getItemViewType(int position) { 89 | int dataLength = mData.size(); 90 | if (dataLength >= criticalCount) { 91 | if ((hide && position == (criticalCount - 1)) || (!hide && position == dataLength)) { 92 | return TYPE_TOGGLE; 93 | } else { 94 | return super.getItemViewType(position); 95 | } 96 | } else { 97 | return super.getItemViewType(position); 98 | } 99 | } 100 | 101 | public void toggle() { 102 | hide = !hide; 103 | notifyDataSetChanged(); 104 | } 105 | 106 | @Override 107 | public void onClick(View v) { 108 | toggle(); 109 | if (expandView != null) { 110 | expandView.setSelected(!hide); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/xbm/expandgridlist/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xbm.expandgridlist; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.GridLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.widget.Toast; 11 | 12 | import com.xbm.expandgridlist.adapter.BaseRVAdapter; 13 | import com.xbm.expandgridlist.adapter.ExpandAdapter; 14 | import com.xbm.expandgridlist.adapter.MovieRVAdapter; 15 | import com.xbm.expandgridlist.bean.MovieBean; 16 | import com.xbm.expandgridlist.decoration.HeaderGridSpacingItemDecoration; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class MainActivity extends AppCompatActivity implements BaseRVAdapter.ItemClickListener { 21 | 22 | private ArrayList movies; 23 | private ArrayList data; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | 30 | //第一种方式 31 | RecyclerView rvList = findViewById(R.id.rv_content); 32 | int spanCount = 6;//跟布局里面的spanCount属性是一致的 33 | GridLayoutManager mgr = new GridLayoutManager(this, spanCount); 34 | rvList.setLayoutManager(mgr); 35 | rvList.setPadding(dip2px(this, 5), 0, dip2px(this, 5), 0); 36 | int spacing = dip2px(this, 5);//每一个矩形的间距 37 | boolean includeEdge = true;//如果设置成false那边缘地带就没有间距 38 | //设置每个item间距 39 | rvList.addItemDecoration(new HeaderGridSpacingItemDecoration(spanCount, spacing, includeEdge, 0)); 40 | movies = new ArrayList<>(); 41 | for (int i = 1; i < 15; i++) { 42 | movies.add(new MovieBean("Movie", String.valueOf(i))); 43 | } 44 | MovieRVAdapter mAdapter = new MovieRVAdapter(12); 45 | rvList.setAdapter(mAdapter); 46 | mAdapter.replaceData(movies); 47 | mAdapter.setItemClickListener(this); 48 | 49 | //第二种方式的伸展布局,相比于第一种不依赖javabean 略解耦 50 | RecyclerView rvList02 = findViewById(R.id.rv_content2); 51 | GridLayoutManager mgr02 = new GridLayoutManager(this, spanCount); 52 | rvList02.setLayoutManager(mgr02); 53 | rvList02.setPadding(dip2px(this, 5), 0, dip2px(this, 5), 0); 54 | //设置每个item间距 55 | rvList02.addItemDecoration(new HeaderGridSpacingItemDecoration(spanCount, spacing, includeEdge, 0)); 56 | data = new ArrayList<>(); 57 | for (int i = 1; i < 25; i++) { 58 | data.add("turn = " + i); 59 | } 60 | ExpandAdapter mAdapter02 = new ExpandAdapter(18); 61 | View expandView = LayoutInflater.from(this).inflate(R.layout.item_toggle, null, false); 62 | mAdapter02.setExpandView(expandView); 63 | mAdapter02.setItemClickListener(new ExpandClickListener()); 64 | rvList02.setAdapter(mAdapter02); 65 | mAdapter02.replaceData(data); 66 | } 67 | 68 | public static int dip2px(Context context, float dipValue) { 69 | final float scale = context.getResources().getDisplayMetrics().density; 70 | return (int) (dipValue * scale + 0.5f); 71 | } 72 | 73 | @Override 74 | public void itemClick(BaseRVAdapter adapter, View view, int position) { 75 | MovieBean bean = (MovieBean) adapter.mData.get(position); 76 | if (bean.isToggle()) { 77 | ((MovieRVAdapter) adapter).toggle(); 78 | } else { 79 | Toast.makeText(MainActivity.this, "turn= " + bean.getTurn() + " content= " + bean.getName(), Toast.LENGTH_SHORT).show(); 80 | } 81 | } 82 | 83 | public class ExpandClickListener implements BaseRVAdapter.ItemClickListener { 84 | 85 | @Override 86 | public void itemClick(BaseRVAdapter adapter, View view, int position) { 87 | Toast.makeText(MainActivity.this, data.get(position), Toast.LENGTH_SHORT).show(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------