Coder Social home page Coder Social logo

maurycyw / staggeredgridview Goto Github PK

View Code? Open in Web Editor NEW
1.6K 1.6K 664.0 808 KB

A modified version of Android's experimental StaggeredGridView. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore.

Home Page: https://github.com/maurycyw/StaggeredGridViewDemo

Groovy 0.95% Java 99.05%

staggeredgridview's People

Contributors

maurycyw avatar tbruyelle avatar vinc3m1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

staggeredgridview's Issues

NullPointerException when number of child Views decreases

hi guys,

sorry in advance to @briangriffey for still being a noob who can't do pull requests.

so basically, StaggeredGridView.layoutChildren() can trigger an NPE when it removes child Views because it iterates on the original number of child Views. the fix is super super simple and i don't have time to learn git so i'm posting it here with fingers crossed that one of the wonderful contributors will add it into the main branch.

both changes are in StaggeredGridView.layoutChildren()

first, we adjust the looping condition.
final int childCount = getChildCount();
int amountRemoved = 0;

for (int i = 0; i < childCount; i++) {
    View child = getChildAt(i);

becomes

final int childCount = getChildCount();
int amountRemoved = 0;

for (int i = 0; i < childCount-amountRemoved; i++) {
    View child = getChildAt(i);
second, we adjust the increment so we don't skip over new ith element.
// child has been removed
removeViewAt(i);
if(i-1>=0) invalidateLayoutRecordsAfterPosition(i-1);
amountRemoved++;
continue;

becomes

// child has been removed
removeViewAt(i);
if(i-1>=0) invalidateLayoutRecordsAfterPosition(i-1);
amountRemoved++;
i--;
continue;

and that's it. hope this helps :)

notifyDataSetChanged(); problem

hi,

how can i return to last position that user were scrolled to , after calling notifyDataSetChanged(); in adapter.

I googled about it and found the method setSelection(int position) but it is used in listview not StaggeredGridView

tanks in advance

setItemMargin breaks scrolling

Using setItemMargin on a multi column gridview prevents up scrolling (towards the first child).

To repeat:

staggered:numColumns="2"
sgv.setItemMargin(10);

Specifying one column or removing the margin call restores normal behaviour.

No means to scroll to a specific item by code

There seems to be no way to scroll the StaggeredGridView to a specific item by code. Using scrollBy() results in a completely broken and misbehaving View (as described in #25 ). This renders this great little library useless for many use cases.

Binary XML file line #9 error

I try it many times but it give me errors...

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.staggeredgridviewdemo/com.example.staggeredgridviewdemo.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.origamilabs.library.views.StaggeredGridView

Can you Please send me 1 full source code example with library ?
If possible then Please mail me:[email protected]

NullPointerException after screen orientation change

I have case when for portrait orientation I have one column and for landscape two columns. If we rotate from portrait to landscape we'll get NullPointerException. Stacktrace:

02-23 19:59:46.772: E/AndroidRuntime(3470): FATAL EXCEPTION: main
02-23 19:59:46.772: E/AndroidRuntime(3470): java.lang.NullPointerException
02-23 19:59:46.772: E/AndroidRuntime(3470):     at com.origamilabs.library.views.StaggeredGridView.populate(StaggeredGridView.java:965)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at com.origamilabs.library.views.StaggeredGridView.onLayout(StaggeredGridView.java:918)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1520)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at com.slidingmenu.lib.CustomViewAbove.onLayout(CustomViewAbove.java:457)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:985)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.View.layout(View.java:14003)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.Choreographer.doFrame(Choreographer.java:532)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.os.Handler.handleCallback(Handler.java:725)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.os.Looper.loop(Looper.java:137)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at android.app.ActivityThread.main(ActivityThread.java:5191)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at java.lang.reflect.Method.invokeNative(Native Method)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at java.lang.reflect.Method.invoke(Method.java:511)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
02-23 19:59:46.772: E/AndroidRuntime(3470):     at dalvik.system.NativeStart.main(Native Method)

image urls other than the ones that come default do not load previews

I've started using this in a new app, and slowly building the app around this library. As a test, I've replaced a few images from a google image search at the front and back end of the list of urls, and they now no longer load. if you'd like to test this, here is my "urls" list:

"http://www.justkiddinggamer.com/wp-content/uploads/2012/06/elizabeth-tran-1.jpg",
"http://photos.modelmayhem.com/photos/130311/14/513e52e2ea67d.jpg",
"http://wwsmag.com/updates/wp-content/uploads/2012/01/400866_341050655914640_248849071801466_1310372_559532474_n.jpg",
"http://technologyinnovator.com/images/nageeyang.jpg",
"http://farm9.staticflickr.com/8208/8219397252_a04e2184b2.jpg",
"http://farm9.staticflickr.com/8483/8218023445_02037c8fda.jpg",
"http://farm9.staticflickr.com/8335/8144074340_38a4c622ab.jpg",
"http://farm9.staticflickr.com/8060/8173387478_a117990661.jpg",
"http://farm9.staticflickr.com/8056/8144042175_28c3564cd3.jpg",
"http://farm9.staticflickr.com/8183/8088373701_c9281fc202.jpg",
"http://farm9.staticflickr.com/8185/8081514424_270630b7a5.jpg",
"http://farm9.staticflickr.com/8462/8005636463_0cb4ea6be2.jpg",
"http://farm9.staticflickr.com/8306/7987149886_6535bf7055.jpg",
"http://farm9.staticflickr.com/8444/7947923460_18ffdce3a5.jpg",
"http://farm9.staticflickr.com/8182/7941954368_3c88ba4a28.jpg",
"http://farm9.staticflickr.com/8304/7832284992_244762c43d.jpg",
"http://farm9.staticflickr.com/8163/7709112696_3c7149a90a.jpg",
"http://farm8.staticflickr.com/7127/7675112872_e92b1dbe35.jpg",
"http://farm8.staticflickr.com/7111/7429651528_a23ebb0b8c.jpg",
"http://farm9.staticflickr.com/8288/7525381378_aa2917fa0e.jpg",
"http://farm6.staticflickr.com/5336/7384863678_5ef87814fe.jpg",
"http://farm8.staticflickr.com/7102/7179457127_36e1cbaab7.jpg",
"http://farm8.staticflickr.com/7086/7238812536_1334d78c05.jpg",
"http://farm8.staticflickr.com/7243/7193236466_33a37765a4.jpg",
"http://farm8.staticflickr.com/7251/7059629417_e0e96a4c46.jpg",
"http://wallaad.com/wp-content/uploads/2013/09/Beautiful-Small-Waterfall-In-Nature-With-Stone-Which-Mossy.jpg"};

The only images that show are the flickr images, the 3 at the front and the one at the back do not load at all.

setItemMargin() disables 'scrolling up'

It worked great until I started to make it look better with setitemMargin()

The view won't scroll up once I set it. and it crashed as well.

I tested on gallaxy s2 with 2.3.3

Items order was changed when reload items.

I use StaggeredGridView to load images in my app,there is a reload function,but when i reload these items,the items order was changed.For example,when I first into the StaggeredGridView,the picture one on the left and picture two on the right,but when I click the reload button,pictures order was changed.
Follow is the reloadItems function,I used LinkedList to holder data.
public void reloadItems(ArrayList<?> items) {
linkedList.clear(); //put data into the LinkedList.
linkedList.addAll(items);
mAdapter.notifydatasetchanged();
}

top images don't align when user flings to the top.

The top of the first left image is placed below the top of the first right image.

`currently restoring position can result in the views to be slightly offset when user flings to the top. This is corrected by checking the offsets when position 0 is reached. '

I'm seeing this issue in my app. How do I fix it as you said 'corrected by checking the offsets when position 0 is reached.'?

Footer for grid

Hi,

If u keep the footer for grid.That would be more helpful.Please add footer....

Crash when using different List Items in StaggeredGridView

When using multiple List Item Type, the recycling view given back to your adapter is wrong type for the asked Type. So it crashes when your code tries to get the viewHolder

It is similar to this issue
http://stackoverflow.com/questions/16526291/listview-with-different-items-and-viewholders-leading-to-classcastexception

When i debugged the code, i found that when offscreen views are added to scrapview List, it was giving wrong ViewType for that view

private void recycleOffscreenViews() {

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        System.out.println("######### recycleOffscreenViews child ######### "+child.getTag().getClass().getCanonicalName()+" : "+lp.viewType);
        mRecycler.addScrap(child);

}

I checked the viewType obtained from the child LayoutParams. It doesn't have the proper value for that view. It was always 0.

So the problem is, in obtainView() function,

    final LayoutParams sglp = (LayoutParams) lp;
    sglp.position = position;
    sglp.viewType = positionViewType;

   // FIX. 
   view.setLayoutParams(sglp);

The layoutParams is not set to the view. Which is why it is always 0 and while adding to ScrapView list.

So after the setting the LayoutParams to the view before returning the view from obtainView() function, everthing works fine. I had tested with 6 different list items in StaggeredGridView. It handles the recycling of views properly.

Scrolling Back up does not work

I am able to scroll down but when I try to scroll up I am unable to.It just seems that the list ends there.
I am facing this problem in android 4.2.2 both on emulator and actual device.

Action needed to work along with sherlock lib

Your lip is really nice.,
i tried to use this.
since i used sherlock and sliding menu lib for slidingmenu and actionbar components.,i cannot use your lib to get StaggeredGridView. giving "Jar Mismatch error" for that jar "Android support lib v4" you had used..

May i know the reason and how can i use your lib?

GridView Reset problem

I am using your StaggeredGridView (which looks awesome btw) with an asynchronous ImageFetcher to fill it.

As it turns out i am having problems when i want to reload the GridView and rebuild it from scratch.

The code i use is:
Images.randomImages.clear(); //the data source of my adapter
m_GridView.setDefaultState(); //i reset the gridView to the default state - i suppose
mAdapter.notifyDataSetChanged(); //notify the adapter

The outcome is:
There are still some images left on the screen and I am not at the top of the screen.
Sometimes one of the columns is not filled with a picture, so there is some empty space.

It would be great if you have a way around that issue. Or am I the only one having trouble with this?

br mikeT

Support space between items

Would be nice if the view had an attribute specifying the spacing between items (vertical and horizontal) like the regular GridView.

Using a workaround right now with padding inside my item-layouts.

Android Studio + Gradle compatibility

Any luck getting this to work with Gradle in Android Studio? It worked fine without Gradle in Android Studio, however when Exporting to Gradle (from Eclipse) all I've achieved is an unforgivable series of faults.

Help. Footer need.

Hello. The code was very helpful.I have any questions.I do not know I try to add a Footer to use any way you want.Me some tips please would be nice.Thank you.

NullPointerException after back to foreground

09-27 15:47:40.352: W/dalvikvm(21531): threadid=1: thread exiting with uncaught exception (group=0x41581700)
09-27 15:47:40.352: E/AndroidRuntime(21531): FATAL EXCEPTION: main
09-27 15:47:40.352: E/AndroidRuntime(21531): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.staggeredgridviewdemo/com.example.staggeredgridviewdemo.activities.MainActivity}: java.lang.NullPointerException
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Looper.loop(Looper.java:137)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-27 15:47:40.352: E/AndroidRuntime(21531): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 15:47:40.352: E/AndroidRuntime(21531): at java.lang.reflect.Method.invoke(Method.java:525)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-27 15:47:40.352: E/AndroidRuntime(21531): at dalvik.system.NativeStart.main(Native Method)
09-27 15:47:40.352: E/AndroidRuntime(21531): Caused by: java.lang.NullPointerException
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readIntArray(Parcel.java:784)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.origamilabs.library.views.StaggeredGridView$SavedState.(StaggeredGridView.java:2108)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.origamilabs.library.views.StaggeredGridView$SavedState.(StaggeredGridView.java:2104)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.origamilabs.library.views.StaggeredGridView$SavedState$1.createFromParcel(StaggeredGridView.java:2132)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.origamilabs.library.views.StaggeredGridView$SavedState$1.createFromParcel(StaggeredGridView.java:1)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readParcelable(Parcel.java:2062)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readValue(Parcel.java:1971)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readSparseArrayInternal(Parcel.java:2284)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readSparseArray(Parcel.java:1693)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readValue(Parcel.java:2028)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Parcel.readMapInternal(Parcel.java:2255)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Bundle.unparcel(Bundle.java:223)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.os.Bundle.getSparseParcelableArray(Bundle.java:1237)
09-27 15:47:40.352: E/AndroidRuntime(21531): at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1644)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.Activity.onRestoreInstanceState(Activity.java:938)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.Activity.performRestoreInstanceState(Activity.java:910)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
09-27 15:47:40.352: E/AndroidRuntime(21531): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2189)
09-27 15:47:40.352: E/AndroidRuntime(21531): ... 11 more

Thx!!!!

Footer

Hi. Appreciate your work. Do you think there should be an easy way of adding a footer view to the grid? Been trying to think of one.

NullPointerExceptin

Hi,

Sometimes getting this error, not sure what causes.

java.lang.NullPointerException
at android.os.Parcel.readIntArray(Parcel.java:678)
com.test.example..StaggeredGridView$SavedState.(StaggeredGridView.java:2105)
com.test.example.viewpager.StaggeredGridView$SavedState.(StaggeredGridView.java:2101)
at com.test.example.viewpager.StaggeredGridView$SavedState$1.createFromParcel(StaggeredGridView.java:2129)
at com.test.example.viewpager.StaggeredGridView$SavedState$1.createFromParcel(StaggeredGridView.java:1)
at android.os.Parcel.readParcelable(Parcel.java:1919)
at android.os.Parcel.readValue(Parcel.java:1784)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2050)
at android.os.Parcel.readSparseArray(Parcel.java:1506)
at android.os.Parcel.readValue(Parcel.java:1841)
at android.os.Parcel.readMapInternal(Parcel.java:2021)
at android.os.Bundle.unparcel(Bundle.java:208)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:1167)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1463)
at android.app.Activity.onRestoreInstanceState(Activity.java:843)
at android.app.Activity.performRestoreInstanceState(Activity.java:815)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2641)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Btw, here is line 2105:

    private SavedState(Parcel in) {
        super(in);
        firstId = in.readLong();
        position = in.readInt();
        in.readIntArray(topOffsets);
        in.readTypedList(mapping, ColMap.CREATOR);  
    }

bug--- in.createIntArray(topOffsets);

private SavedState(Parcel in) {
super(in);
firstId = in.readLong();
position = in.readInt();
in.createIntArray(topOffsets);
in.readTypedList(mapping, ColMap.CREATOR);

    }

Include LICENSE

Some of the files have Apache License Headers, but a full license should probably be included in the repo

customize selection color

hi,

thanks for this awesome view btw. i noticed there was no way of customizing the selection color so i added in this feature. unfortunately, i'm a total git and github noob and since the changes are super simple, i figured i'd post them here and cross my fingers they end up in the main source rather than learn to make pull requests.

i added 2 lines:
a. in res/values/attrs.xml, add this line with the other attribute declarations

<attr name="selector" format="color|reference" />

b. in src/.../StaggeredGridView.java, add this line inside the StaggeredGridView(Context context, AttributeSet attrs, int defStyle) constructor, alongside the other attribute parsings

mSelector = a.getDrawable(R.styleable.StaggeredGridView_selector);

that's it! sorry for being useless with git. hope you enjoy the new feature!

UI gets disturbed when navigating across the screens.

Hi everything works great for me except one issue. Gridview layout is not getting inflated in a correct way in my application.

When my layout is loaded the gridview is rendering with let's say 4x4 column in my tablet(10" Sony Xperia Z) in landscape mode, but sometime somewhere at any random row number the items are not rendering sequentially but at any random position with uneven void space. It frequently changes the order of images when navigating across the screens as well.

The same type of situation arise when the tablet is in the portrait mode. but surprisingly when the orientation changes then this issue is getting resolved automatically. I've also attached the image representing my issue. for more information you can go at http://stackoverflow.com/questions/20400626/staggeredgridview-layout-inflation-issue where i posted question regarding this.

Regards.
staggere_image

NullPointerException in onTouchEvent

No idea how to repeat it. It occasionally happen.

java.lang.NullPointerException
    at com.origamilabs.library.views.StaggeredGridView.onTouchEvent(SourceFile:545)
    at android.view.View.dispatchTouchEvent(View.java:7143)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2238)

The line number may be slightly different at my local version. It refers to the "if" line and the NPE is caused by a null mAdapter in "mAdapter.isEnabled(motionPosition)". A patch is as follows:


    public boolean onTouchEvent(MotionEvent ev) {
                /**
                 * PATCHED: mAdapter may cause NPE
                 */
                if (!mDataChanged && mAdapter!=null && mAdapter.isEnabled(motionPosition)) { /** line 545 */
                    // TODO : handle
                    mTouchMode = TOUCH_MODE_TAP;
                } else {
                    mTouchMode = TOUCH_MODE_REST;
                }

Scrolling issues

Scrolling down is working great however when I want to scroll up it does not work. I was testing it on Nexus 7, Android 4.2.1

Selector behaves abnormally when screen orientation changes

To repeat:

Open demo app and press one item, the selector behaves normally, then change the screen orientation to landscape mode, press the same item, you will see the abnormal selector which its color becomes much darker than normal color.
If this doesn't happen, you'd better change the screen orientation and press the same item for more time.

Does "span" option work?

If I have 3 columns and I set the "span" option to "2", I have this error:

12-21 10:50:35.104: E/AndroidRuntime(9418): FATAL EXCEPTION: main
12-21 10:50:35.104: E/AndroidRuntime(9418): java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
12-21 10:50:35.104: E/AndroidRuntime(9418):     at com.origamilabs.library.views.StaggeredGridView.fillDown(StaggeredGridView.java:1430)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at com.origamilabs.library.views.StaggeredGridView.populate(StaggeredGridView.java:972)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at com.origamilabs.library.views.StaggeredGridView.onLayout(StaggeredGridView.java:918)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.View.layout(View.java:14003)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:985)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.View.layout(View.java:14003)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.View.layout(View.java:14003)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.View.layout(View.java:14003)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.View.layout(View.java:14003)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.Choreographer.doFrame(Choreographer.java:532)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.os.Handler.handleCallback(Handler.java:725)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.os.Looper.loop(Looper.java:137)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at android.app.ActivityThread.main(ActivityThread.java:5191)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at java.lang.reflect.Method.invokeNative(Native Method)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at java.lang.reflect.Method.invoke(Method.java:511)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
12-21 10:50:35.104: E/AndroidRuntime(9418):     at dalvik.system.NativeStart.main(Native Method)

My code:

        if (convertView == null) {
            LayoutInflater layoutInflator = LayoutInflater.from(getContext());
            convertView = layoutInflator.inflate(R.layout.row_staggered_demo,
                    null);
            StaggeredGridView.LayoutParams layoutParams = new StaggeredGridView.LayoutParams(StaggeredGridView.LayoutParams.WRAP_CONTENT);
            layoutParams.span = 2;
            convertView.setLayoutParams(layoutParams);
            holder = new ViewHolder();
            holder.imageView = (ScaleImageView) convertView .findViewById(R.id.imageView1);
            convertView.setTag(holder);
        }

How to change text and images dynamically

You library seems promising but i want to know how could i change the text and image dynamically. Let say if i get data from Http server and then create staggered grid view

Clearing animations on removed children

Hi there!

Thank you very much for developing this widget!

I found something while playing with it: in "private void recycleAllViews()", when "removeAllViews();" is called you should add "clearDisappearingChildren();" to clear ongoing animations from the removed child views. It took me a day to figure it out :) (it caused me an animation is hovering in empty space... :) )

Best regards

column count to be auto ?

Can the column count have an auto variable which can be adjusted based on screen width and children width ??

Display nothing, why?

I had set adapter for it, but nothing display, is there anything I mistake?

--update--
The adapter method "getView" nerver be invoked.

--Resolve--
Need to invoke adapter "notifyDatasetChanged" method at first render.

My device is Samsung i9001, Android 2.3.6

A column could offset some distance down when screen orientation changes

To repeat:

Scroll to list bottom and then change the screen orientation, if the current orientation is portrait, you will see a large blank on the bottom and when you scroll to list top and you will see one column offsets some distance. Else if the current orientation is landscape, just scroll to list top directly, you will see the same phenomenon.

Multiple childs get switched to their selected state when using custom drawable for background

I have about 30 childs in the StaggeredGridView. The GridView implements the StaggeredGridView.OnItemClickListener. When clicking or long clicking the items (which have their custom drawables states defined), multiple childs get the "clicked" state. They all turn the light blue as if they are being focused.

I define the view like this:

    <com.origamilabs.library.views.StaggeredGridView
        android:id="@+id/staggered_list"
        staggered:numColumns="@integer/cols"
        staggered:drawSelectorOnTop="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

The top child view has a custom drawable with different states:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/item_state"
    android:descendantFocusability="blocksDescendants"
    android:padding="10dp" >

I tried playing with the drawSelectorOnTop value, but it wouldn't work.

Item selector remains when scrolling

To repeat:

Press any item and hold on until selector shows and then scroll the list. You will see the selector remains even then you scroll over a screen.

ScrollTo move whole layout not just content!

When I use staggeredView.scrollTo(0, 100); it change the views offset to the top.
A margin is created and items in the list over the point y=100 cant be viewed, you cant scroll over y=100. Also the touch becomes twisted, when you press a point in the view a point 100 px over it gets pressed.
What can i do to fix this?

Sorry for the bad English!

Sample app is buggy : shows empty spaces and has bad scrolling

I've tested the sample app, and sadly I've noticed some weird bugs, which include presenting empty cells (sometimes tall ones) and sometimes the scrolling barely scroll anything.

All that I know is that it occurs more frequently when I change the orientation frequently.

Has anyone else got those weird bugs?
Is there a workaround or alternative to this library?

EDIT: it seems it is caused because the sample doesn't set the size of the items right away, but only after the images were loaded.
however, it doesn't explain the empty cells issue.
i've used Volley library instead of what is used in the sample, and i've used a constant height for the cells depending on their position on the array (for example, 1/5 of the screen height in case it's even, or 1/3 in case it's not).

ContextMenu option instead of LongPress?

This library may be the answer fo an app I'm working on, but I had a question. While you have a listener for longpressing, what if oyu want to display a context menu? Sure, you could just inflate a layout into a popup dialog "on long press", but can I instead just assign a contextMenu to the view? If so, would the position get passed as normal?

edit, never mind, looks like you can call the included code already:

AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;

Top and Bottom notifications and possible animations

I am wondering if it would be possible to add three things to this view.

The first two would be a notification when you have scrolled to the top of the list and a notification for when you have scrolled to the bottom. My thinking here is something like Google+ where if you are at the top of the list and something new comes along it will be added to the top of the list and if you scroll to the bottom, it loads some older items and displays them. I thought this would not be too difficult, but I am not certain. Would this be placed in the fillUp and fillDown functions?

I was also wondering if it would be possible to use animations when at the bottom of the list also similar to Google+. if you are at the bottom of the list it checks for older items and then the next visible items float up from the bottom of the page.

The Listener Problem

I cannot set any listener in StaggeredGridView item.
like this :

gridView.setOnItemClickListener(new OnItemClickListener() {
@OverRide
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

        }
    });

Please help me about that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.