Android RecyclerView 网格显示正方形
16lz
2021-01-23
使用recyclerView显示纵向滑动的网格列表,只需要设置
mListView.setLayoutManager(new GridLayoutManager(context,4));
public class MyLayout extends RelativeLayout {
public MyLayout (Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle);}public MyLayout (Context context, AttributeSet attrs) { super(context, attrs);}public MyLayout (Context context) { super(context);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); int childWidthSize = getMeasuredWidth(); // 高度和宽度一样 heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec( childWidthSize, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec);}
}
更多相关文章
- Android文字垂直滚动、纵向走马灯的几种实现方式
- portrait表示纵向,landscape表示横向
- Android网格布局的简单使用
- portrait表示横向,landscape表示纵向
- Android RecyclerView网格布局的学习
- 横向 纵向结合的ScrollView
- Android 中使用代码动态网格布局