检查你的 item 布局的最外层是否是

android:layout_width="match_parent"

附加均匀分布的方法

// 创建布局管理

     GridLayoutManager manager = new GridLayoutManager(getContext(),2,GridLayoutManager.VERTICAL,false);rv_organ.addItemDecoration(new SpaceItemDecoration(0,2));rv_organ.setLayoutManager(manager);public class SpaceItemDecoration extends RecyclerView.ItemDecoration {private int leftRight;private int topBottom;// leftRight 为横向间的距离 topBottom为纵向间距离public SpaceItemDecoration(int leftRight, int topBottom) {this.leftRight = leftRight;this.topBottom = topBottom;}@Overridepublic void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {super.onDraw(c, parent, state);}@Overridepublic void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();// 竖直方向的if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {// 最后一项需要 bottomif (parent.getChildAdapterPosition(view) == layoutManager.getItemCount() - 1) {outRect.bottom = topBottom;}outRect.top = topBottom;outRect.left = leftRight;outRect.right = leftRight;} else {// 最后一项需要 rightif (parent.getChildAdapterPosition(view) == layoutManager.getItemCount() - 1) {outRect.right = leftRight;}outRect.top = topBottom;outRect.left = leftRight;outRect.bottom = topBottom;}}}

Android --- GridLayoutManager 设置了 item 均匀分布,但是无效相关推荐

  1. Android PullToRefreshListView设置各个item之间的间距

    要设置第三方的上拉下载listView的item之间的间距,可以在xml布局文件中的listView节点中设置xml的属性即可: android:divider="#00000000&quo ...

  2. android listview设置选中时的item的背景色

    今天实在不知道写些什么内容,所以自己在网上找了些资料,觉得还可以,所以还是写一下,觉得每天写些东西的习惯不能荒废. 默认情况下使用ListView背景色是黑色,选中item的高亮颜色是菊黄色,很多时候 ...

  3. 【RecyclerView】 十四、GridLayoutManager 网格布局管理器 ( GridLayoutManager.SpanSizeLookup 指定 item 元素占用网格个数 )

    文章目录 一.修改单条数据 二.完整代码示例 三.总体运行效果 四.RecyclerView 相关资料 一.修改单条数据 GridLayoutManager.SpanSizeLookup 的主要作用是 ...

  4. Android RecyclerView设置分割线 / 下拉加载 / 选项菜单进行增加删除动画

    首先看一下我的整个程序: 主类: package com.example.day02rk;import android.os.Bundle; import android.support.v4.con ...

  5. android开发设置dialog的高宽

    这里设置为跟屏幕一样的宽度,:看代码 dlg.show();WindowManager.LayoutParams params = dlg.getWindow().getAttributes(); p ...

  6. Android ListView 设置

    android:minHeight="80dip"//设置每一条的高度 android:divider="@null" //设置默认的分割线不显示 androi ...

  7. android roboto字体下载,Android字体设置及Roboto字体使用方法

    本文实例讲述了Android字体设置及Roboto字体使用方法.分享给大家供大家参考.具体分析如下: 一.自定义字体 1.android Typeface使用TTF字体文件设置字体 我们可以在程序中放 ...

  8. 解决listview中的textview设置了setMovementMethod导致onItemclick无效的问题

    前提: 当listview的item 中有textview,且textview中内容使用了spannablestring,并且需要点击事件(如超链接等),为textview设置了setMovement ...

  9. android webview设置加载进度条

    1.自定义属性文件--attrs.xml <?xml version="1.0" encoding="utf-8"?> <resources& ...

最新文章

  1. 视觉人工智能市场格局初成型,国内企业占半壁江山
  2. java B2B2C springmvc mybatis电子商务平台源码-Consul服务发现原理...
  3. yolo类检测算法解析——yolo v3
  4. python 倒叙 数组_打基础一定要吃透这12类 Python 内置函数
  5. MySQL数据库的终结_MySQL数据库秘籍终结 对不起了 让你们自宫了 其实不消哈哈哈...
  6. android应用程序的组件,Android基础之应用程序组件
  7. easyui中combotree只能选子选项,父级不被选中
  8. python 有限域函数库_深入比特币之有限域运算
  9. python import pandas报错找不到_扎心!“我学了半年 Python,还是找不到工作”
  10. SpringSecurity框架【详解】
  11. 张一鸣辞职,没那么简单
  12. Redis的五种存储类型和其应用场景
  13. JzxxOJ 1299 半斤八两 题解
  14. flutter-学习之发布安卓包APK
  15. PLC属于电子计算机吗,plc是什么
  16. Apache Ant简介
  17. 怎样恢复计算机到桌面,电脑任务栏怎么还原到下面 电脑任务栏还原方法【图文】...
  18. 《C语言点滴》一第1章 程序猿 程序媛1.1 装备篇
  19. RS Meet DL(68)-建模多任务学习中任务相关性的模型MMoE
  20. 青少年科技大赛 计算机课题,科技活动----22届青少年科技创新大赛中的活动方案3...

热门文章

  1. Java基础-特殊数据类型:枚举
  2. 基于混合储能的并网光伏发电系统仿真
  3. Intel qsv + ffmpeg 硬解h264
  4. cv::parallel_for_ 的一个例子
  5. Go语言简单的TCP编程
  6. Flask-hello程序
  7. Caffe官方教程翻译(4):CIFAR-10 turorial
  8. 吴恩达深度学习课程deeplearning.ai课程作业:Class 2 Week 1 1.Initialization
  9. 随机组卷python_关于随机自动组卷的算法,二维数组
  10. Linux 内核101:[译]并发导论