├── 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 │ │ │ ├── layout │ │ │ │ ├── item_2.xml │ │ │ │ ├── item_1.xml │ │ │ │ ├── item_1_origin.xml │ │ │ │ ├── item_2_origin.xml │ │ │ │ └── activity_main.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── menu │ │ │ │ └── toolbar_menu.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── joker │ │ │ └── recyclerviewtest │ │ │ ├── ArrayListWrapper.java │ │ │ ├── Item2.java │ │ │ ├── Item1.java │ │ │ ├── RecyclerViewWrapper.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── joker │ │ │ └── recyclerviewtest │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── joker │ │ └── recyclerviewtest │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── apk └── app-debug.apk ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /apk/app-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/apk/app-debug.apk -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RecyclerViewTest 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [手摸手第二弹,可视化 RecyclerView 缓存机制](https://juejin.im/post/5a5d3d9b518825734216e1e8) 2 | 3 | [about ListView](https://github.com/jokermonn/ListViewVisualization) -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jokermonn/RecyclerViewVisualization/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/jokermonn/RecyclerViewVisualization/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/jokermonn/RecyclerViewVisualization/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/jokermonn/RecyclerViewVisualization/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/jokermonn/RecyclerViewVisualization/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/layout/item_2.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Jan 07 22:09:45 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.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFC107 4 | #FFA000 5 | #FFC107 6 | #00796B 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_1.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /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/test/java/com/joker/recyclerviewtest/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.joker.recyclerviewtest; 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 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_1_origin.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_2_origin.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/menu/toolbar_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/joker/recyclerviewtest/ArrayListWrapper.java: -------------------------------------------------------------------------------- 1 | package com.joker.recyclerviewtest; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ArrayListWrapper extends ArrayList { 6 | public int maxSize = 0; 7 | public boolean canReset = true; 8 | private int lastSize = 0; 9 | 10 | @Override public boolean remove(Object o) { 11 | if (size() > maxSize) { 12 | maxSize = size(); 13 | canReset = false; 14 | } 15 | if (size() == 0) { 16 | canReset = true; 17 | } 18 | return super.remove(o); 19 | } 20 | 21 | @Override public boolean add(T t) { 22 | if (canReset) { 23 | if (size() + 1 > lastSize) { 24 | maxSize = size() + 1; 25 | } 26 | } 27 | return super.add(t); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /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/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/joker/recyclerviewtest/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.joker.recyclerviewtest; 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.joker.recyclerviewtest", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/joker/recyclerviewtest/Item2.java: -------------------------------------------------------------------------------- 1 | package com.joker.recyclerviewtest; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.util.AttributeSet; 6 | import android.widget.LinearLayout; 7 | import android.widget.TextView; 8 | 9 | public class Item2 extends LinearLayout { 10 | private TextView tv; 11 | 12 | public Item2(Context context) { 13 | this(context, null); 14 | } 15 | 16 | public Item2(Context context, 17 | @Nullable AttributeSet attrs) { 18 | this(context, attrs, 0); 19 | } 20 | 21 | public Item2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 22 | super(context, attrs, defStyleAttr); 23 | inflate(context, R.layout.item_2_origin, this); 24 | tv = findViewById(R.id.tv_content); 25 | } 26 | 27 | @Override public String toString() { 28 | return "Item2---" + tv.getText(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/joker/recyclerviewtest/Item1.java: -------------------------------------------------------------------------------- 1 | package com.joker.recyclerviewtest; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.util.AttributeSet; 6 | import android.widget.LinearLayout; 7 | import android.widget.TextView; 8 | 9 | public class Item1 extends LinearLayout { 10 | private TextView tv; 11 | 12 | public Item1(Context context) { 13 | this(context, null); 14 | } 15 | 16 | public Item1(Context context, 17 | @Nullable AttributeSet attrs) { 18 | this(context, attrs, 0); 19 | } 20 | 21 | public Item1(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 22 | super(context, attrs, defStyleAttr); 23 | inflate(context, R.layout.item_1_origin, this); 24 | tv = findViewById(R.id.tv_content); 25 | } 26 | 27 | @Override public String toString() { 28 | return "Item1---『" + tv.getText() + "』"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.joker.recyclerviewtest" 7 | minSdkVersion 21 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(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | implementation 'com.android.support:recyclerview-v7:26.1.0' 29 | } 30 | -------------------------------------------------------------------------------- /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/java/com/joker/recyclerviewtest/RecyclerViewWrapper.java: -------------------------------------------------------------------------------- 1 | package com.joker.recyclerviewtest; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.AttributeSet; 7 | import java.lang.reflect.Field; 8 | import java.util.ArrayList; 9 | 10 | public class RecyclerViewWrapper extends RecyclerView { 11 | private LayoutListener listener; 12 | 13 | public RecyclerViewWrapper(Context context) { 14 | super(context); 15 | } 16 | 17 | public RecyclerViewWrapper(Context context, 18 | @Nullable AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | public RecyclerViewWrapper(Context context, @Nullable AttributeSet attrs, int defStyle) { 23 | super(context, attrs, defStyle); 24 | } 25 | 26 | public interface LayoutListener { 27 | void beforeLayout(); 28 | 29 | void afterLayout(); 30 | } 31 | 32 | public void setLayoutListener(LayoutListener listener) { 33 | this.listener = listener; 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | public void reflectObject(RecyclerViewWrapper recyclerViewWrapper) { 38 | try { 39 | Field mRecycler = 40 | Class.forName("android.support.v7.widget.RecyclerView").getDeclaredField("mRecycler"); 41 | mRecycler.setAccessible(true); 42 | RecyclerView.Recycler recyclerInstance = 43 | (RecyclerView.Recycler) mRecycler.get(recyclerViewWrapper); 44 | 45 | Class recyclerClass = Class.forName(mRecycler.getType().getName()); 46 | Field mAttachedScrap = recyclerClass.getDeclaredField("mAttachedScrap"); 47 | mAttachedScrap.setAccessible(true); 48 | mAttachedScrap.set(recyclerInstance, new ArrayListWrapper()); 49 | 50 | ArrayList mAttached = 51 | (ArrayList) mAttachedScrap.get(recyclerInstance); 52 | } catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | 57 | @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { 58 | if (listener != null) { 59 | listener.beforeLayout(); 60 | } 61 | super.onLayout(changed, l, t, r, b); 62 | if (listener != null) { 63 | listener.afterLayout(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 25 | 26 | 34 | 35 | 46 | 47 | 53 | 54 | 60 | 61 | 62 | 63 |