Android 自动换行流式布局的RadioGroup
效果图
用法
使用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的更多相关文章
- Android流式布局实现
查看我的所有开源项目[开源实验室] 欢迎增加我的QQ群:[201055521],本博客client下载[请点击] 摘要 新项目用到了一种全新布局----Android标签流式布局的功能,正好一直说给大 ...
- 自定义ViewGroup 流式布局
使用 public class MainActivity extends Activity { @Override protected void onCreate(Bundle sav ...
- Android 自定义View修炼-Android中常见的热门标签的流式布局的实现
一.概述:在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧(源码下载在下面最后给出哈) 类似的 ...
- Android控件进阶-自定义流式布局和热门标签控件
技术:Android+java 概述 在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧,类 ...
- 含有过滤功能的android流式布局
FilterFlowLayout 含有过滤功能的流式布局, 參考FlowLayout 能够去除宽度不在范围(比例或真实值)内的子view 能够设置最大行数 能够加入组件间水平间距 能够加入行间距 系统 ...
- 【Android - 自定义View】之自定义可滚动的流式布局
首先来介绍一下这个自定义View: (1)这个自定义View的名称叫做 FlowLayout ,继承自ViewGroup类: (2)在这个自定义View中,用户可以放入所有继承自View类的视图,这个 ...
- android -------- 流式布局,支持单选、多选等
最近开发中有流式标签这个功能,网上学了下,来分享一下 Android 流式布局,支持单选.多选等,适合用于产品标签等. 效果图: 用法: dependencies { compile 'com.hym ...
- android流式布局、待办事项应用、贝塞尔曲线、MVP+Rxjava+Retrofit、艺术图片应用等源码
Android精选源码 android模仿淘宝首页效果源码 一款艺术图片应用,采用T-MVVM打造 Android MVP + RxJava + Retrofit项目 android流式布局实现热门标 ...
- Android自己定义之流式布局
流式布局,优点就是父类布局能够自己主动的推断子孩子是不是须要换行,什么时候须要换行,能够做到网页版的标签的效果. 今天就是简单的做了自己定义的流式布局. 详细效果: 原理: 事实上非常easy,Mea ...
随机推荐
- 一步步学习ASP.NET MVC3 章节总结
请注明转载地址:http://www.cnblogs.com/arhat 对于<一步步学习ASP.NET MVC3>系列工15章,那么为了方便大家能够快速的预览,老魏在这里为这个系列提供一 ...
- 微软职位内部推荐-Sr DEV Lead, Bing Search Relevance
微软近期Open的职位: Contact Person: Winnie Wei (wiwe@microsoft.com )Sr DEV Lead, Bing Search RelevanceLocat ...
- 0ffice365 Calendar API
Calendar REST API in Office 365 APIs Preview http://msdn.microsoft.com/EN-US/library/office/dn792114 ...
- Solr + Hadoop = Big Data Love
FROM:http://architects.dzone.com/articles/solr-hadoop-big-data-love 许多人使用Hadoop的开源项目来处理大数据的大数据集,因为它是 ...
- 机器学习基石的泛化理论及VC维部分整理(第六讲)
第六讲 第五讲主要讲了机器学习可能性,两个问题,(1)\(E_{in} 要和 E_{out}\) 有很接近,(2)\(E_{in}\)要足够小. 对于第一个假设,根据Hoefding's Inequa ...
- 机器学习基石的泛化理论及VC维部分整理
第四讲 机器学习的可行性 一.Hoeffding's Inequality \(P[\left | \nu -\mu \right |>\epsilon ] \leq 2exp(-2\epsi ...
- 【概率】poj 2096:Collecting Bugs
Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...
- asp.net中@ Import 命令的使用
@ Import 将命名空间显式导入到 ASP.NET 应用程序文件(如网页.用户控件.母版页或 Global.asax 文件)中,同时使导入的命名空间的所有类和接口可用于文件.导入的命名空间可以是 ...
- AlphaGo 已经战胜了李世石,而你还不知道什么是机器学习?
谷歌人工智能 AlphaGo 与韩国棋手李世石 3 月 15 日进行了最后一场较量,最终比赛结果为 AlphaGo 4:1 胜李世石,人机围棋大战巅峰对决至此落幕.我不知道大家有没有被震撼到,反正我的 ...
- ICMP and InetAddress.isReachable()
In Java it is only possible to work with two types of sockets: stream based ones (or TCP ones - java ...