Is it possible to create pinterest like layout on Android using GridView
? I want to create image gallery using GridView
but I am not sure if it is good solution. I do not want create three LinearLayouts
(I think that this solution is not good: Pinterest style listview or gridview in android)
Any ideas ;)?
A GridView is a type of AdapterView that displays items in a two-dimensional scrolling grid. Items are inserted into this grid layout from a database or from an array.
The main function of the adapter in GridView is to fetch data from a database or array and insert each piece of data in an appropriate item that will be displayed in GridView. This is how the GridView structure looks like. Note that we are going to implement this project using the Java language.
Create an XML file for each grid item to be displayed in GridView. Click on the app > res > layout > Right-Click > Layout Resource file and then name the file as card_item. Below is the code for the card_item.xml file.
android:numColumns: This attribute of GridView will be used to decide the number of columns that are to be displayed in Grid. android:horizontalSpacing: This attribute is used to define the spacing between two columns of GridView. android:verticalSpacing: This attribute is used to specify the spacing between two rows of GridView.
I've been playing with this also (used LinearLayout) but at the end I had lot of problems with memory consumption (especially when I had to reload the items). I settled on simple solution which uses two synchronized ListViews. This way I can exploit internal caching which helps a lot. To do this I had to use OnTouchListener and OnScrollListener who synchronize lists. Here's an example:
https://github.com/vladexologija/PinterestListView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With