GridLayoutManager inherits from LinearLayoutManager and is the layout manager of RecyclerView, mainly to realize grid layout.
GridLayoutManager.setOrientation(GridLayoutManager.VERTICAL)Or HORIZONTALmay be provided in the extending direction of RecyclerView, VERTICAL is, that extend in the longitudinal direction.
new GridLayoutManager(this, row)Or setSpanCount(row)you can set the number of ranks RecyclerView, in particular a row or column, you need to look at setOrientation(), is VERTICAL is refers to the number of rows.
setOrientation(GridLayoutManager.VERTICAL)+ layout_width="match_parent"Allow RecyclerView to adapt to the width in the horizontal direction;
setOrientation(GridLayoutManager.HORIZONTAL)+ layout_height="match_parent"Allows RecyclerView to be highly adaptive in the vertical direction;
Width and height bidirectional adaptive padding (Why am I so cheap, so many methods, I have to use RecyclerView)
Take setOrientation(GridLayoutManager.VERTICAL)+ layout_width="match_parent"as an example. At this time, the horizontal direction is adaptive, and the vertical direction is infinitely extended.
The Item is android:layout_heightset to"match_parent"
Custom LinearLayout (each item of mine is a LinearLayout, take this example), write the onMeasure method
@OverrideprotectedvoidonMeasure(int widthMeasureSpec,int heightMeasureSpec){
int newHeightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec)/ line, EXACTLY);super.onMeasure(widthMeasureSpec, newHeightMeasureSpec);}
Here lineis the number of rows
Modify LinearLayout in XML to be customized, the effect is as follows