├── settings.gradle ├── art └── art.gif ├── handygridview ├── gradle.properties ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── huxq17 │ │ │ └── handygridview │ │ │ ├── scrollrunner │ │ │ ├── ICarrier.java │ │ │ ├── OnItemMovedListener.java │ │ │ ├── OnceRunnable.java │ │ │ └── ScrollRunner.java │ │ │ ├── listener │ │ │ ├── IDrawer.java │ │ │ └── OnItemCapturedListener.java │ │ │ ├── utils │ │ │ ├── SdkVerUtils.java │ │ │ ├── ReflectUtil.java │ │ │ └── Pools.java │ │ │ ├── Children.java │ │ │ ├── Child.java │ │ │ └── HandyGridView.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── huxq17 │ │ └── handygridview │ │ └── ExampleInstrumentedTest.java ├── build.gradle ├── .gitignore ├── proguard-rules.pro └── gradle-jcenter-push.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── app ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── ids.xml │ │ │ ├── styles.xml │ │ │ ├── dimens.xml │ │ │ └── strings.xml │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ ├── ic_delete.png │ │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── menu │ │ │ └── menu_main.xml │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ ├── drawable │ │ │ └── s_grid_item.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── handygridview │ │ └── example │ │ ├── DensityUtil.java │ │ ├── widget │ │ ├── CustomLinearLayout.java │ │ └── TagView.java │ │ ├── GridViewAdapter.java │ │ └── MainActivity.java ├── proguard-rules.pro ├── build.gradle └── .gitignore ├── .gitattributes ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':handygridview' 2 | -------------------------------------------------------------------------------- /art/art.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/art/art.gif -------------------------------------------------------------------------------- /handygridview/gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/handygridview/gradle.properties -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/app/src/main/res/drawable-xhdpi/ic_delete.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxq17/HandyGridView/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HandyGridView 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 20 18:04:23 CST 2017 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 | -------------------------------------------------------------------------------- /handygridview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/scrollrunner/ICarrier.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.scrollrunner; 2 | 3 | 4 | import android.content.Context; 5 | 6 | public interface ICarrier { 7 | Context getContext(); 8 | 9 | void onMove(int lastX, int lastY, int curX, int curY); 10 | 11 | void onDone(); 12 | 13 | boolean post(Runnable runnable); 14 | 15 | boolean removeCallbacks(Runnable action); 16 | } 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/listener/IDrawer.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.listener; 2 | 3 | import android.graphics.Canvas; 4 | 5 | 6 | public interface IDrawer { 7 | /** 8 | * You can draw something in gridview by this method. 9 | * 10 | * @param canvas 11 | * @param width the gridview's width 12 | * @param height the gridview's height 13 | */ 14 | void onDraw(Canvas canvas, int width, int height); 15 | } 16 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/listener/OnItemCapturedListener.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.listener; 2 | 3 | import android.view.View; 4 | 5 | public interface OnItemCapturedListener { 6 | /** 7 | * Called when user selected a view to drag. 8 | * 9 | * @param v 10 | */ 11 | void onItemCaptured(View v,int position); 12 | 13 | /** 14 | * Called when user released the drag view. 15 | * 16 | * @param v 17 | */ 18 | void onItemReleased(View v,int position); 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/s_grid_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/utils/SdkVerUtils.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.utils; 2 | 3 | import android.os.Build; 4 | 5 | /** 6 | * Created by Administrator on 2017/11/26. 7 | */ 8 | 9 | public class SdkVerUtils { 10 | public static boolean isAboveVersion(int version) { 11 | int sdkVersion = Build.VERSION.SDK_INT; 12 | if (sdkVersion >= version) { 13 | return true; 14 | } 15 | return false; 16 | } 17 | 18 | public static boolean isAbove19() { 19 | return isAboveVersion(Build.VERSION_CODES.KITKAT); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/scrollrunner/OnItemMovedListener.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.scrollrunner; 2 | 3 | public interface OnItemMovedListener { 4 | /** 5 | * Called when user moved the item of gridview. 6 | * you should swipe data in this method. 7 | * @param from item's original position 8 | * @param to item's destination poisition 9 | */ 10 | void onItemMoved(int from, int to); 11 | 12 | /** 13 | * return true if the item of special position can not move. 14 | * @param position 15 | * @return 16 | */ 17 | boolean isFixed(int position); 18 | } 19 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\xiaolin\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | applicationId "com.handygridview.example" 8 | minSdkVersion 14 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | api fileTree(include: ['*.jar'], dir: 'libs') 23 | api 'com.android.support:appcompat-v7:28.0.0' 24 | // compile 'com.android.support.constraint:constraint-layout:1.0.2' 25 | api project(':handygridview') 26 | // api 'com.huxq17.handygridview:handygridview:1.1.0' 27 | } 28 | -------------------------------------------------------------------------------- /handygridview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | android { 3 | compileSdkVersion 28 4 | 5 | defaultConfig { 6 | minSdkVersion 11 7 | targetSdkVersion 26 8 | versionCode 1 9 | versionName "1.0" 10 | 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | //for upload jar 23 | buildscript { 24 | repositories { 25 | jcenter() 26 | } 27 | dependencies { 28 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' 29 | } 30 | } 31 | apply from: 'gradle-jcenter-push.gradle' 32 | 33 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/scrollrunner/OnceRunnable.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.scrollrunner; 2 | 3 | import android.view.View; 4 | 5 | public abstract class OnceRunnable implements Runnable { 6 | private boolean mScheduled; 7 | 8 | public final void run() { 9 | onRun(); 10 | mScheduled = false; 11 | } 12 | 13 | public abstract void onRun(); 14 | 15 | public void postSelf(View carrier) { 16 | postDelaySelf(carrier, 0); 17 | } 18 | 19 | public void postDelaySelf(View carrier, int delay) { 20 | if (!mScheduled) { 21 | carrier.postDelayed(this, delay); 22 | mScheduled = true; 23 | } 24 | } 25 | 26 | public void removeSelf(View carrier) { 27 | mScheduled = false; 28 | carrier.removeCallbacks(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | # Keystore files 39 | *.jks 40 | 41 | # External native build folder generated in Android Studio 2.2 and later 42 | .externalNativeBuild 43 | 44 | # Google Services (e.g. APIs or Firebase) 45 | google-services.json 46 | 47 | # Freeline 48 | freeline.py 49 | freeline/ 50 | freeline_project_description.json 51 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | # Keystore files 39 | *.jks 40 | 41 | # External native build folder generated in Android Studio 2.2 and later 42 | .externalNativeBuild 43 | 44 | # Google Services (e.g. APIs or Firebase) 45 | google-services.json 46 | 47 | # Freeline 48 | freeline.py 49 | freeline/ 50 | freeline_project_description.json 51 | -------------------------------------------------------------------------------- /handygridview/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | # Keystore files 39 | *.jks 40 | 41 | # External native build folder generated in Android Studio 2.2 and later 42 | .externalNativeBuild 43 | 44 | # Google Services (e.g. APIs or Firebase) 45 | google-services.json 46 | 47 | # Freeline 48 | freeline.py 49 | freeline/ 50 | freeline_project_description.json 51 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /handygridview/src/androidTest/java/com/huxq17/handygridview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.HandyGridView; 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 | * Instrumentation 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.huxq17.moveongridview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /handygridview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/utils/ReflectUtil.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.utils; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | public class ReflectUtil { 8 | public static Object invokeMethod(Object targetObject, String methodName, Object[] params, Class[] paramTypes) { 9 | Object returnObj = null; 10 | if (targetObject == null || TextUtils.isEmpty(methodName)) { 11 | return null; 12 | } 13 | Method method = null; 14 | for (Class cls = targetObject.getClass(); cls != Object.class; cls = cls.getSuperclass()) { 15 | try { 16 | method = cls.getDeclaredMethod(methodName, paramTypes); 17 | break; 18 | } catch (Exception e) { 19 | // e.printStackTrace(); 20 | // return null; 21 | } 22 | } 23 | if (method != null) { 24 | method.setAccessible(true); 25 | try { 26 | returnObj = method.invoke(targetObject, params); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | return returnObj; 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/handygridview/example/DensityUtil.java: -------------------------------------------------------------------------------- 1 | package com.handygridview.example; 2 | 3 | import android.content.Context; 4 | 5 | public class DensityUtil { 6 | 7 | /** 8 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 9 | */ 10 | public static int dip2px(Context context, float dpValue) { 11 | final float scale = getScale(context); 12 | return (int) (dpValue * scale + 0.5f); 13 | } 14 | 15 | /** 16 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 17 | */ 18 | public static int px2dip(Context context, float pxValue) { 19 | final float scale = getScale(context); 20 | return (int) (pxValue / scale + 0.5f); 21 | } 22 | 23 | public static int px2sp(Context context, float pxValue) { 24 | final float fontScale = getScale(context); 25 | return (int) (pxValue / fontScale + 0.5f); 26 | } 27 | 28 | public static int sp2px(Context context, float spValue) { 29 | final float fontScale = getScale(context); 30 | return (int) (spValue * fontScale + 0.5f); 31 | } 32 | 33 | private static float getScale(Context context) { 34 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 35 | return findScale(fontScale); 36 | } 37 | private static float findScale(float scale){ 38 | if(scale<=1){ 39 | scale=1; 40 | }else if(scale<=1.5){ 41 | scale=1.5f; 42 | }else if(scale<=2){ 43 | scale=2f; 44 | }else if(scale<=3){ 45 | scale=3f; 46 | } 47 | return scale; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/Children.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview; 2 | 3 | import android.view.View; 4 | 5 | import java.util.Iterator; 6 | import java.util.LinkedHashMap; 7 | import java.util.LinkedList; 8 | 9 | public class Children { 10 | private LinkedHashMap container = new LinkedHashMap<>(); 11 | private LinkedList mChildren = new LinkedList<>(); 12 | private HandyGridView parent; 13 | 14 | public Children(HandyGridView parent) { 15 | this.parent = parent; 16 | } 17 | 18 | public void add(int index, View view) { 19 | Child child = container.get(view); 20 | if (child == null) { 21 | child = new Child(view); 22 | child.setParent(parent); 23 | container.put(view, child); 24 | } 25 | mChildren.add(index, child); 26 | } 27 | 28 | public boolean remove(Child child) { 29 | return mChildren.remove(child); 30 | } 31 | 32 | public void remove(int index) { 33 | mChildren.remove(index); 34 | } 35 | 36 | public Child get(int index) { 37 | return mChildren.get(index); 38 | } 39 | 40 | public int indexOf(View v) { 41 | Child child = container.get(v); 42 | if (child == null) { 43 | return -2; 44 | } 45 | return mChildren.indexOf(child); 46 | } 47 | 48 | public int size() { 49 | return mChildren.size(); 50 | } 51 | 52 | public void clear() { 53 | container.clear(); 54 | Iterator it = mChildren.iterator(); 55 | //子view从gridView移除时取消动画效果 56 | while (it.hasNext()) { 57 | Child child = it.next(); 58 | child.cancel(); 59 | it.remove(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/handygridview/example/widget/CustomLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.handygridview.example.widget; 2 | 3 | 4 | import android.content.Context; 5 | import android.support.annotation.Nullable; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.LinearLayout; 9 | 10 | import com.huxq17.handygridview.HandyGridView; 11 | 12 | 13 | public class CustomLinearLayout extends LinearLayout { 14 | public CustomLinearLayout(Context context) { 15 | super(context); 16 | } 17 | 18 | public CustomLinearLayout(Context context, @Nullable AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | public CustomLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 23 | super(context, attrs, defStyleAttr); 24 | } 25 | 26 | private int mGridViewIndex = -1; 27 | 28 | @Override 29 | protected void onAttachedToWindow() { 30 | super.onAttachedToWindow(); 31 | int count = getChildCount(); 32 | for (int i = 0; i < count; i++) { 33 | View child = getChildAt(i); 34 | if (child instanceof HandyGridView) { 35 | HandyGridView HandyGridView = (HandyGridView) child; 36 | if (HandyGridView.isLongPressMode() || HandyGridView.isTouchMode()) { 37 | setChildrenDrawingOrderEnabled(true); 38 | mGridViewIndex = i; 39 | } 40 | return; 41 | } 42 | } 43 | } 44 | 45 | @Override 46 | protected int getChildDrawingOrder(int childCount, int i) { 47 | int index = i; 48 | if (mGridViewIndex != -1) { 49 | if (i == mGridViewIndex) { 50 | index = childCount - 1; 51 | } else if (i == childCount - 1) { 52 | index = mGridViewIndex; 53 | } 54 | } 55 | return index; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /handygridview/src/main/java/com/huxq17/handygridview/scrollrunner/ScrollRunner.java: -------------------------------------------------------------------------------- 1 | package com.huxq17.handygridview.scrollrunner; 2 | 3 | 4 | import android.view.animation.Interpolator; 5 | import android.view.animation.LinearInterpolator; 6 | import android.widget.Scroller; 7 | 8 | public class ScrollRunner implements Runnable { 9 | private Scroller mScroller; 10 | private ICarrier mCarrier; 11 | private int mDuration = 250; 12 | private int lastX, lastY; 13 | 14 | public ScrollRunner(ICarrier carrier) { 15 | this(carrier, new LinearInterpolator()); 16 | } 17 | 18 | public ScrollRunner(ICarrier carrier, Interpolator interpolator) { 19 | mCarrier = carrier; 20 | mScroller = new Scroller(carrier.getContext(), interpolator); 21 | } 22 | 23 | public void setCarrier(ICarrier carrier) { 24 | mCarrier = carrier; 25 | } 26 | 27 | public void start(int dx, int dy) { 28 | start(dx, dy, mDuration); 29 | } 30 | 31 | public void start(int dx, int dy, int duration) { 32 | start(0, 0, dx, dy, duration); 33 | } 34 | 35 | public void start(int startX, int startY, int dx, int dy) { 36 | start(startX, startY, dx, dy, mDuration); 37 | } 38 | 39 | public void start(int startX, int startY, int dx, int dy, int duration) { 40 | this.mDuration = duration; 41 | mScroller.startScroll(startX, startY, dx, dy, duration); 42 | mCarrier.removeCallbacks(this); 43 | mCarrier.post(this); 44 | lastX = startX; 45 | lastY = startY; 46 | } 47 | 48 | public void cancel() { 49 | if (!mScroller.isFinished()) { 50 | mCarrier.removeCallbacks(this); 51 | mScroller.forceFinished(true); 52 | } 53 | } 54 | 55 | public int getCurX() { 56 | return mScroller.getCurrX(); 57 | } 58 | 59 | public int getCurY() { 60 | return mScroller.getCurrY(); 61 | } 62 | 63 | public void abortAnimation() { 64 | if (!mScroller.isFinished()) { 65 | mScroller.abortAnimation(); 66 | } 67 | } 68 | 69 | public boolean isRunning() { 70 | return !mScroller.isFinished(); 71 | } 72 | 73 | @Override 74 | public void run() { 75 | if (mScroller.computeScrollOffset()) { 76 | int currentX = mScroller.getCurrX(); 77 | int currentY = mScroller.getCurrY(); 78 | mCarrier.onMove(lastX, lastY, currentX, currentY); 79 | lastX = currentX; 80 | lastY = currentY; 81 | if (currentX == mScroller.getFinalX() && currentY == mScroller.getFinalY()) { 82 | mCarrier.removeCallbacks(this); 83 | mCarrier.onDone(); 84 | } else { 85 | mCarrier.post(this); 86 | } 87 | } else { 88 | mCarrier.removeCallbacks(this); 89 | mCarrier.onDone(); 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 27 | 28 | 31 | 32 | 40 | 41 | 44 | 45 | 52 | 53 | 56 | 57 | 60 | 61 | 69 | 70 | 73 | 74 |