I am working in android material design api & want to display some data in grid format. I tried both GridLayout
and StaggeredGridlayout
and both look same. For general information, i want to ask what is the difference between Gridlayout
and StaggeredGridlayout
?
Thank you.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
My time at Oodles Technologies taught me about staggered. I'll share that.
StaggeredGridLayout is a LayoutManager, it is just like a grid view but in this grid each view have its own size(height and width). It supports both vertical and horizontal layouts.
Below are some basic steps to create a staggered grid-
1) Create a view.
As we know staggeredgrid is not a direct view it is a layoutmanager that lays out children in a staggered grid formation. We use RecyclerView as a view for staggerd grid. here is our recyclerview in layout-
2) Set StaggeredGridLayout LayoutManager.
Once our view is ready, let's use Layoutmanager to create grids on the view.
3) Adapter to inflate the staggeredgrid views.
To inflate the data in form of grid first we need a layout which will represent that data.We are using CardView for this and the layout is-
Then We setup our all the basic steps, it's time to complete our main activity. here is the complete code of main activity-
Grid View : It is is a
ViewGroup
that displays items in a two-dimensional, scrollable grid. In this each Grid is of same size (Height and width). Grid View shows symmetric items in view.Staggered Grid View : It is basically an extension to
Grid View
but in this each Grid is of varying size(Height and width). Staggered Grid View shows asymmetric items in view.Tutorial to implement Staggered Grid View :
StaggeredGridlayout
StaggeredGridLayoutManager
can offset spans independently or move items between spans. You can control this behavior viasetGapStrategy(int)
.GridLayout
rowSpec
andcolumnSpec
layout parameters.A staggered grid Layout includes multiple columns with multiple rows of varying sizes.
It allows for a flexible column/row view with a header and footer and looks fairly easy to implement, though Gradle users will have an easier time than those working with Eclipse and Ant. This is what the view looks like in the Etsy Github app for which it was developed.
Whereas a GridLayout is a layout that places its children in a rectangular grid.
It was introduced in API level 14, and was recently backported in the Support Library. Its main purpose is to solve alignment and performance problems in other layouts. Check out this tutorial if you want to learn more about GridLayout.
Grid Layout (API Level 14): A layout that places its children in a rectangular grid. The number of rows and columns within the grid can be declared using the
android:rowCount
andandroid:columnCount
properties. Typically, however, if the number of columns is declared the GridLayout will infer the number of rows based on the number of occupied cells making the use of the rowCount property unnecessary. Similarly, the orientation of the GridLayout may optionally be defined via theandroid:orientation
property.I think there is no separate StaggeredGridLayout. Here are the things we do have
StaggeredGridLayoutManager : It is one of the a layout manager used in Recyclerview.A LayoutManager that lays out children in a staggered grid formation. It supports horizontal & vertical layout as well as an ability to layout children in reverse.
Staggered GridView : The StaggeredGridView allows the user to create a GridView with uneven rows similar to how Pinterest looks. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore.Please look at this example.