效果图

用法

使用FlowRadioGroup代替RadioGroup

代码

  1. import android.content.Context;
  2. import android.util.AttributeSet;
  3. import android.view.View;
  4. import android.widget.RadioGroup;
  5.  
  6. /**
  7. * 流式布局的RadioGroup
  8. */
  9. public class FlowRadioGroup extends RadioGroup {
  10.  
  11. public FlowRadioGroup(Context context) {
  12. super(context);
  13. }
  14.  
  15. public FlowRadioGroup(Context context, AttributeSet attrs) {
  16. super(context, attrs);
  17. }
  18.  
  19. @Override
  20. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  21. int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
  22. int childCount = getChildCount();
  23. int x = 0;
  24. int y = 0;
  25. int row = 0;
  26.  
  27. for (int index = 0; index < childCount; index++) {
  28. final View child = getChildAt(index);
  29. if (child.getVisibility() != View.GONE) {
  30. child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
  31. // 此处增加onlayout中的换行判断,用于计算所需的高度
  32. int width = child.getMeasuredWidth();
  33. int height = child.getMeasuredHeight();
  34. x += width;
  35. y = row * height + height;
  36. if (x > maxWidth) {
  37. x = width;
  38. row++;
  39. y = row * height + height;
  40. }
  41. }
  42. }
  43. // 设置容器所需的宽度和高度
  44. setMeasuredDimension(maxWidth, y);
  45. }
  46.  
  47. @Override
  48. protected void onLayout(boolean changed, int l, int t, int r, int b) {
  49. final int childCount = getChildCount();
  50. int maxWidth = r - l;
  51. int x = 0;
  52. int y = 0;
  53. int row = 0;
  54. for (int i = 0; i < childCount; i++) {
  55. final View child = this.getChildAt(i);
  56. if (child.getVisibility() != View.GONE) {
  57. int width = child.getMeasuredWidth();
  58. int height = child.getMeasuredHeight();
  59. x += width;
  60. y = row * height + height;
  61. if (x > maxWidth) {
  62. x = width;
  63. row++;
  64. y = row * height + height;
  65. }
  66. child.layout(x - width, y - height, x, y);
  67. }
  68. }
  69. }
  70. }

Android 自动换行流式布局的RadioGroup的更多相关文章

  1. Android流式布局实现

    查看我的所有开源项目[开源实验室] 欢迎增加我的QQ群:[201055521],本博客client下载[请点击] 摘要 新项目用到了一种全新布局----Android标签流式布局的功能,正好一直说给大 ...

  2. 自定义ViewGroup 流式布局

    使用 public class MainActivity extends Activity {     @Override     protected void onCreate(Bundle sav ...

  3. Android 自定义View修炼-Android中常见的热门标签的流式布局的实现

    一.概述:在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧(源码下载在下面最后给出哈) 类似的 ...

  4. Android控件进阶-自定义流式布局和热门标签控件

    技术:Android+java   概述 在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧,类 ...

  5. 含有过滤功能的android流式布局

    FilterFlowLayout 含有过滤功能的流式布局, 參考FlowLayout 能够去除宽度不在范围(比例或真实值)内的子view 能够设置最大行数 能够加入组件间水平间距 能够加入行间距 系统 ...

  6. 【Android - 自定义View】之自定义可滚动的流式布局

    首先来介绍一下这个自定义View: (1)这个自定义View的名称叫做 FlowLayout ,继承自ViewGroup类: (2)在这个自定义View中,用户可以放入所有继承自View类的视图,这个 ...

  7. android -------- 流式布局,支持单选、多选等

    最近开发中有流式标签这个功能,网上学了下,来分享一下 Android 流式布局,支持单选.多选等,适合用于产品标签等. 效果图: 用法: dependencies { compile 'com.hym ...

  8. android流式布局、待办事项应用、贝塞尔曲线、MVP+Rxjava+Retrofit、艺术图片应用等源码

    Android精选源码 android模仿淘宝首页效果源码 一款艺术图片应用,采用T-MVVM打造 Android MVP + RxJava + Retrofit项目 android流式布局实现热门标 ...

  9. Android自己定义之流式布局

    流式布局,优点就是父类布局能够自己主动的推断子孩子是不是须要换行,什么时候须要换行,能够做到网页版的标签的效果. 今天就是简单的做了自己定义的流式布局. 详细效果: 原理: 事实上非常easy,Mea ...

随机推荐

  1. 一步步学习ASP.NET MVC3 章节总结

    请注明转载地址:http://www.cnblogs.com/arhat 对于<一步步学习ASP.NET MVC3>系列工15章,那么为了方便大家能够快速的预览,老魏在这里为这个系列提供一 ...

  2. 微软职位内部推荐-Sr DEV Lead, Bing Search Relevance

    微软近期Open的职位: Contact Person: Winnie Wei (wiwe@microsoft.com )Sr DEV Lead, Bing Search RelevanceLocat ...

  3. 0ffice365 Calendar API

    Calendar REST API in Office 365 APIs Preview http://msdn.microsoft.com/EN-US/library/office/dn792114 ...

  4. Solr + Hadoop = Big Data Love

    FROM:http://architects.dzone.com/articles/solr-hadoop-big-data-love 许多人使用Hadoop的开源项目来处理大数据的大数据集,因为它是 ...

  5. 机器学习基石的泛化理论及VC维部分整理(第六讲)

    第六讲 第五讲主要讲了机器学习可能性,两个问题,(1)\(E_{in} 要和 E_{out}\) 有很接近,(2)\(E_{in}\)要足够小. 对于第一个假设,根据Hoefding's Inequa ...

  6. 机器学习基石的泛化理论及VC维部分整理

    第四讲 机器学习的可行性 一.Hoeffding's Inequality \(P[\left | \nu -\mu  \right |>\epsilon ] \leq 2exp(-2\epsi ...

  7. 【概率】poj 2096:Collecting Bugs

    Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...

  8. asp.net中@ Import 命令的使用

    @ Import  将命名空间显式导入到 ASP.NET 应用程序文件(如网页.用户控件.母版页或 Global.asax 文件)中,同时使导入的命名空间的所有类和接口可用于文件.导入的命名空间可以是 ...

  9. AlphaGo 已经战胜了李世石,而你还不知道什么是机器学习?

    谷歌人工智能 AlphaGo 与韩国棋手李世石 3 月 15 日进行了最后一场较量,最终比赛结果为 AlphaGo 4:1 胜李世石,人机围棋大战巅峰对决至此落幕.我不知道大家有没有被震撼到,反正我的 ...

  10. ICMP and InetAddress.isReachable()

    In Java it is only possible to work with two types of sockets: stream based ones (or TCP ones - java ...