用法

使用FlowRadioGroup代替RadioGroup

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RadioGroup;/*** 流式布局的RadioGroup*/
public class FlowRadioGroup extends RadioGroup {public FlowRadioGroup(Context context) {super(context);}public FlowRadioGroup(Context context, AttributeSet attrs) {super(context, attrs);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int maxWidth = MeasureSpec.getSize(widthMeasureSpec);int childCount = getChildCount();int x = 0;int y = 0;int row = 0;for (int index = 0; index < childCount; index++) {final View child = getChildAt(index);if (child.getVisibility() != View.GONE) {child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);// 此处增加onlayout中的换行判断,用于计算所需的高度int width = child.getMeasuredWidth();int height = child.getMeasuredHeight();x += width;y = row * height + height;if (x > maxWidth) {x = width;row++;y = row * height + height;}}}// 设置容器所需的宽度和高度
        setMeasuredDimension(maxWidth, y);}@Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b) {final int childCount = getChildCount();int maxWidth = r - l;int x = 0;int y = 0;int row = 0;for (int i = 0; i < childCount; i++) {final View child = this.getChildAt(i);if (child.getVisibility() != View.GONE) {int width = child.getMeasuredWidth();int height = child.getMeasuredHeight();x += width;y = row * height + height;if (x > maxWidth) {x = width;row++;y = row * height + height;}child.layout(x - width, y - height, x, y);}}}
}

转载于:https://www.cnblogs.com/zhujiabin/p/6033412.html

Android 自动换行流式布局的RadioGroup相关推荐

  1. 流式布局的RadioGroup

    当我们使用RadioGroup时,如果文字信息较多的时候不会展示出来..这个时候我们需要重新对RadioGroup进行处理,当信息过多的时候自动换行 也就是大家所说的流布局样式的RadioGroup ...

  2. android recyclerview流式布局,Android FlexboxLayout流式布局

    Android FlexboxLayout流式布局 FlexBoxLayout是为Android带来了与 CSS Flexible Box Layout(CSS 弹性盒子)相似功能的库. 一:添加依赖 ...

  3. Android FlowLayout流式布局

    最近使用APP的时候经常看到有 这种流式布局 ,今天我就跟大家一起来动手撸一个这种自定义控件. 首先说一下自定义控件的流程: 自定义控件一般要么继承View要么继承ViewGroup View的自定义 ...

  4. Android FlowLayout 流式布局

    FlowLayout 流式布局 Android 流式布局控件,实现自动换行,操出范围可以滑动功能,未使用控件复用功能,所以不应该有太多的子控件. 主要包含功能: 流式布局,自动换行 使用Adapter ...

  5. Android自定义流式布局-FlowLayout

    很多App在搜索页时都有对热门标签的一个排列,而Android官方没有对应的布局控件,所以自己写了一个流式布局(也称标签布局)--FlowLayout. 为了大家使用的方便,没有添加自定义属性,所以需 ...

  6. Android第三方流式布局FlowLayout简单实用(搜索历史记录)

    效果图: 导入大Model下: maven { url 'https://jitpack.io' } builde.gradle依赖: implementation 'com.github.LRH19 ...

  7. android分组流式布局,Android 流式布局实现

    概述 本文主要分享Android流式布局实现,实现效果如下: 在实现之前先来看一下View的生命周期,如下图: 流式布局属于自定义ViewGroup,重点关注onMeasure与onLayout方法 ...

  8. android自定义流式布局思路,Android 自定义控件基础-流式布局

    什么是流式布局?其实我们在平时遇到过,只是有可能叫不出它的名字. 如图: 如上图,就是一个流式布局的样式. &esmp;这里,将记录一下怎么实现这个功能.其实实现这个功能的方法,就是自定义Vi ...

  9. android自适应流式布局,流式布局(完整版)

    1.首先创建一个自定义View类: public class CustomView extends ViewGroup { private int mleftMargin=20; private in ...

最新文章

  1. String和int 转换
  2. java中Object类的hashCode和equals及toString方法。
  3. php 未定义偏移,未定义的偏移PHP错误,尝试从文件读取
  4. Xamarin Android提示内存溢出错误
  5. selenium速度_RPA UiPath和Selenium,谁是测试套件?
  6. Spring-beans架构设计原理
  7. 计算机二本生不学编程还能干什么6,不建议二本考生报考的6个专业,除非真的感兴趣!...
  8. java swing总结,Java 实用经验总结 Swing 篇
  9. 使用SAP WebIDE创建开发Java应用,并且在浏览器里调试
  10. 神圣的傻瓜,善良的杰克·凯鲁亚克:纪念《在路上》50年
  11. Thread的run()与start()的区别
  12. 安卓日志点击无反应_长生之路游戏原型开发日志(三十七)
  13. java JDK设置环境变量
  14. CAS学习笔记(三)—— SERVER登录后用户信息的返回
  15. 吴恩达机器学习中文视频链接
  16. NRF52840学习——GPIO输入,实现按键短按和长按
  17. 比例电磁阀(二)阀门开度与速度的关系
  18. 财务会计科目与预算会计科目关联对照表
  19. discuz模板文件说明
  20. 微信小程序实战十三:狗狗小程序云搭建

热门文章

  1. python批量读取图片并复制入word_提取出 Word 文档里的图片 并利用 python 批量转换格式...
  2. oracle last day比较,PLSQL LAST_DAY用法及代码示例
  3. 3dmax java_Java3D读取3DMax模型并实现鼠标拖拽、旋转、滚轮缩放等功能
  4. python计算相关性显著性p值_基于python实现计算两组数据P值
  5. python语音库_Python中的Python文本到语音
  6. linux进程被杀掉日志,Linux进程突然被杀掉(OOM killer),查看系统日志
  7. 外架小横杆外露长度规范要求_电缆制作通用工艺规范
  8. relative和absolute使用
  9. java freemarker_Java: FreeMarker的配置和使用
  10. springboot 文件服务器_spring boot还不了解?一份spring boot实战文档送给你