Android heterogeneous gridview how pinterest?

Is it possible to create pinterest as a layout on Android using a GridView ? I want to create an image gallery using GridView , but I'm not sure if this is a good solution. I don't want to create three LinearLayouts (I think this solution is not very good: Pinterest-style listview or gridview in android )

Any ideas;)?

enter image description here

+53
java android design pinterest
Jul 31 2018-12-12T00:
source share
7 answers

Create the layout as shown below.

 <ScrollView...> <LinearLayout.... android:id="@+id/linear1" orientation="horizontal"> <LinearLayout.... android:id="@+id/linear2" android:layout_weight="0.33" orientation="vertical"> <LinearLayout.... android:id="@+id/linear3" android:layout_weight="0.33" orientation="vertical"> <LinearLayout.... android:layout_weight="0.33" orientation="vertical"> </LinearLayout> </ScrollView> 

Now dynamically add ImageView to layouts

 linear1 = (LinearLayout) findViewById(R.id.linear1); linear2 = (LinearLayout) findViewById(R.id.linear2); linear3 = (LinearLayout) findViewById(R.id.linear3); for(int i=0;i<n;i++) { ImageView iv = new ImageView(this); iv.setImageResource(R.id.icon); int j = count % 3; <---- if(j==0) linear1.addView(iv); else if(j==1) linear2.addView(iv); else linear3.addView(iv); } 

exit:

enter image description here

+21
Jul 31 '12 at 9:12
source share

I also played with this (used LinearLayout), but in the end I had a lot of problems with memory consumption (especially when I had to reload items). I settled on a simple solution that uses two synchronized ListViews . This way I can use internal caching which helps a lot. To do this, I had to use OnTouchListener and OnScrollListener , which synchronize the lists. Here is an example:

https://github.com/vladexologija/PinterestListView

enter image description here

+25
Sep 21 '12 at 8:32
source share

A separate assistant for synchronizing scrolling from 2 lists: https://gist.github.com/yanchenko/6179793

+6
Jan 24 '13 at 10:05
source share

For recent visitors to this question, I would suggest using RecyclerView with the StaggedGridLayoutManager . It has more than enough features and flexibility.

+6
May 13, '15 at 7:00 a.m.
source share

I am using this lib: https://github.com/huewu/PinterestLikeAdapterView .

It works very well. The only problem I came across is that setOnItemClickListener and setOnItemLongClickListener bit wrong, so I set the listeners directly in the convertView.

+3
Aug 09 '13 at 3:29
source share

This library comes from the Etsy app: https://github.com/etsy/AndroidStaggeredGrid

+2
Jan 03 '14 at 13:03
source share



All Articles