效果图

用法

使用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);
} @Override
protected 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);
} @Override
protected 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);
}
}
}
}

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. 使用OpenXml操作Excel,以下方法用于在添加列时修改Cell的CellReference属性。

    以下方法实现了递增Excel中单元格的CellReference的功能,只支持两位字母. public static string CellReferenceIncrement(string cell ...

  2. ofbiz进阶之框架配置文件指导

    The Open For Business Project: Framework Configuration Guide 原文链接:http://ofbiz.apache.org/docs/corec ...

  3. You have new mail in /var/spool/mail/root 烦不烦你?

    http://blog.csdn.net/yx_l128125/article/details/7425182

  4. nodejs phantom add click event

    page.evaluate( function() { // find element to send click to var element = document.querySelector( ' ...

  5. bnuoj 29368 Check the Identity(栈)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=29368 [题解]:模拟,然后对x,进行枚举,看是否所有都满足条件 [code]: #include ...

  6. 100 doors

    Question There are 100 doors in a row that are all initially closed. You make 100 passes by the door ...

  7. 3123 高精度练习之超大整数乘法 - Wikioi

    题目描述 Description 给出两个正整数A和B,计算A*B的值.保证A和B的位数不超过100000位. 输入描述 Input Description 读入两个用空格隔开的正整数 输出描述 Ou ...

  8. 1874: [BeiJing2009 WinterCamp]取石子游戏 - BZOJ

    Description小H和小Z正在玩一个取石子游戏. 取石子游戏的规则是这样的,每个人每次可以从一堆石子中取出若干个石子,每次取石子的个数有限制,谁不能取石子时就会输掉游戏. 小H先进行操作,他想问 ...

  9. cf 320B

    数据量小  dfs水过 #include <iostream> #include <cstdio> #include <cstring> using namespa ...

  10. 论MOBA类游戏五号位的重要性

    观众朋友们,也许你对题目很好奇,才打开这篇文章.为什么技术圈中会出现游戏类的软文?如果时间充足,可以继续往下看. MOBA 类游戏的兴起,逐渐吞噬游戏市场,以病毒式的扩张方式肆意改变着游戏玩家内心对游 ...