├── .gitignore ├── AndroidManifest.xml ├── README.md ├── ant.properties ├── build.xml ├── libs ├── android-support-v4.jar └── picasso-2.0.0.jar ├── proguard-project.txt ├── project.properties ├── res ├── anim │ ├── slide_in_from_bottom.xml │ ├── slide_in_from_top.xml │ ├── slide_out_to_bottom.xml │ └── slide_out_to_top.xml ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-ldpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ ├── default_ptr_flip.png │ ├── default_ptr_rotate.png │ ├── ic_launcher.png │ └── indicator_arrow.png ├── drawable │ ├── indicator_bg_bottom.xml │ └── indicator_bg_top.xml ├── layout │ ├── ac_main.xml │ ├── ac_stgv.xml │ ├── ac_stgv_with_ptr.xml │ ├── cell_stgv.xml │ ├── layout_loading_footer.xml │ ├── pull_to_refresh_header_horizontal.xml │ └── pull_to_refresh_header_vertical.xml └── values │ ├── ptr_attrs.xml │ ├── ptr_dimens.xml │ ├── ptr_ids.xml │ ├── ptr_strings.xml │ ├── stgv_attrs.xml │ └── strings.xml ├── snapshot └── snap.png └── src └── com ├── bulletnoid └── android │ └── widget │ ├── StaggeredGridView │ ├── HeaderFooterListAdapter.java │ ├── ScrollerCompat.java │ ├── ScrollerCompatIcs.java │ └── StaggeredGridView.java │ └── StaggeredGridViewDemo │ ├── DataSet.java │ ├── Item.java │ ├── MainActivity.java │ ├── STGVActivity.java │ ├── STGVAdapter.java │ ├── STGVImageView.java │ └── STGVWithPTRActivity.java └── handmark └── pulltorefresh └── library ├── ILoadingLayout.java ├── IPullToRefresh.java ├── LoadingLayoutProxy.java ├── OverscrollHelper.java ├── PullToRefreshAdapterViewBase.java ├── PullToRefreshBase.java ├── PullToRefreshExpandableListView.java ├── PullToRefreshGridView.java ├── PullToRefreshHorizontalScrollView.java ├── PullToRefreshListView.java ├── PullToRefreshScrollView.java ├── PullToRefreshStaggeredGridView.java ├── PullToRefreshWebView.java ├── extras ├── PullToRefreshWebView2.java └── SoundPullEventListener.java └── internal ├── EmptyViewMethodAccessor.java ├── FlipLoadingLayout.java ├── IndicatorLayout.java ├── LoadingLayout.java ├── RotateLoadingLayout.java ├── Utils.java └── ViewCompat.java /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # IntelliJ project files 23 | .idea/ 24 | *.iml 25 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | StaggeredGridView 2 | ================= 3 | 4 | ## A sweeter StaggeredGridView 5 | 6 | This widget is based on [maurycyw/StaggeredGridView][1], which is a modification of Android's experimental StaggeredGridView: [com.android.ex.widget.StaggeredGridView][2] 7 | 8 | This widget has fixed some of the major bugs and has some new features that you may be interested. 9 | 10 | ![](snapshot/snap.png) 11 | 12 | ## Suggestion 13 | 14 | It is very helpful for you to use this widget in your app and understand the restriction in it if you had knowledge of how to create Android custom views; 15 | http://developer.android.com/guide/topics/ui/custom-components.html has good information about that; 16 | 17 | ## Features 18 | 19 | * Stability and high performance 20 | 21 | This widget fix some bugs of [maurycyw/StaggeredGridView][1]. Such as when fling the view, the scroll sometimes slow down and speed up later. 22 | 23 | Notice that the image loading also has a contribution to the performance. I use [square/Picasso][3], it provides the best performance I've ever seen. 24 | * Header and Footer View and an Adapter to wrap all child views, just like android.widget.ListView 25 | 26 | Header and footer views can cross columns, but the widget currently only support no more than one header and no more than one footer. 27 | * Load more when get to the bottom 28 | 29 | You may find the footer view useful here. 30 | * Work with PullToRefresh 31 | 32 | A compatible part enable this widget to be pulled to refresh. 33 | 34 | ## Restriction 35 | 36 | * You have to determine the dimension of each child view in the widget before the parent the child.measure() 37 | 38 | This is because the after the child is first time added to the parent widget, its size should not be changed, otherwise it may cause gird misalign as you may have seen in [maurycyw/StaggeredGridView][1]. 39 | 40 | eg. You want to display pictures in the widget, and the pictures are loaded from network. 41 | The height of each grid is decided by the size of the picture in them. 42 | Say, if you set your picture container to WRAP_CONTENT, the size of the pic container may change when the picture is loaded, and then the size of the grid change. 43 | This can cause gird misalign. 44 | Unfortunately, the current methodology has nothing to do to fix this. 45 | Instead, you can let this widget know the size of each child before the picture is actually downloaded. 46 | You can do this by overwrite the onMeasure() method of the container. 47 | 48 | * Load more is lazy 49 | 50 | When load more, the widget only add new items to the old ones, the old ones is not reloaded. 51 | 52 | * Screen rotation 53 | 54 | The widget may have problem holding the state when it is destroyed and restored the them in a different screen orientation. 55 | Besides, you may want to change the column number when the screen orientation changed, you'd better rebuild the whole content from start. 56 | 57 | ## Project structure 58 | 59 | Project contains StaggeredGridView library, StaggeredGridView demo, modified PullToRefresh library to work with StaggeredGridView. 60 | In order to avoid some dependency problems, I add the libs into one project, but it is easy to retrieve the libs. 61 | * StaggeredGridView lib 62 | 63 | code: src/com.bulletoid.android.widget.StaggeredGridView 64 | 65 | res: res/stgv_*.xml 66 | * PullToRefresh lib 67 | 68 | code: src/com.handmark.pulltorefresh.library 69 | 70 | res: res/ptr_*.xml 71 | 72 | ## Usage 73 | 74 | Please refer to the Demo of how to use the widget and use it with PullToRefresh. 75 | 76 | ## Pictures in the demo are from Pinterest 77 | 78 | License 79 | -------- 80 | 81 | 82 | Licensed under the Apache License, Version 2.0 (the "License"); 83 | you may not use this file except in compliance with the License. 84 | You may obtain a copy of the License at 85 | 86 | http://www.apache.org/licenses/LICENSE-2.0 87 | 88 | Unless required by applicable law or agreed to in writing, software 89 | distributed under the License is distributed on an "AS IS" BASIS, 90 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 91 | See the License for the specific language governing permissions and 92 | limitations under the License. 93 | 94 | 95 | [1]: https://github.com/maurycyw/StaggeredGridView 96 | [2]: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/com/android/ex/widget/StaggeredGridView.java?av=f 97 | [3]: https://github.com/square/picasso 98 | -------------------------------------------------------------------------------- /ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/libs/android-support-v4.jar -------------------------------------------------------------------------------- /libs/picasso-2.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/libs/picasso-2.0.0.jar -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-18 15 | 16 | -------------------------------------------------------------------------------- /res/anim/slide_in_from_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /res/anim/slide_in_from_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /res/anim/slide_out_to_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /res/anim/slide_out_to_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/default_ptr_flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-xhdpi/default_ptr_flip.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/default_ptr_rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-xhdpi/default_ptr_rotate.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/indicator_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bulletnoid/StaggeredGridView/77b7d52aa707fd10c74b98e540b966929bfc66c6/res/drawable-xhdpi/indicator_arrow.png -------------------------------------------------------------------------------- /res/drawable/indicator_bg_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 17 | 18 | -------------------------------------------------------------------------------- /res/drawable/indicator_bg_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 17 | 18 | -------------------------------------------------------------------------------- /res/layout/ac_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |