当前位置: 首页 > news >正文

无锡网站制作网站燕郊做网站的

无锡网站制作网站,燕郊做网站的,南浔哪有做网站的,排名前十的室内设计公司Android可换行的RadioGroup,有时候需要换行显示的单选列表#xff0c;当然可以有多种实现方式#xff0c;比如recycleview或者listview实现#xff0c;本文采用的是RadioGrouprediobutton方式实现。 一、首先自定义view public class WrapRadioGroup extends RadioGroup {pr…        Android可换行的RadioGroup,有时候需要换行显示的单选列表当然可以有多种实现方式比如recycleview或者listview实现本文采用的是RadioGrouprediobutton方式实现。 一、首先自定义view public class WrapRadioGroup extends RadioGroup {private static final String TAG RadioGroupEx;public WrapRadioGroup(Context context) {super(context);}public WrapRadioGroup(Context context, AttributeSet attrs) {super(context, attrs);}Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int widthSize MeasureSpec.getSize(widthMeasureSpec);int widthMode MeasureSpec.getMode(widthMeasureSpec);int heightSize MeasureSpec.getSize(heightMeasureSpec);int heightMode MeasureSpec.getMode(heightMeasureSpec);//调用ViewGroup的方法测量子viewmeasureChildren(widthMeasureSpec, heightMeasureSpec);//最大的宽int maxWidth 0;//累计的高int totalHeight 0;//当前这一行的累计行宽int lineWidth 0;//当前这行的最大行高int maxLineHeight 0;//用于记录换行前的行宽和行高int oldHeight;int oldWidth;int count getChildCount();//假设 widthMode和heightMode都是AT_MOSTfor (int i 0; i count; i) {View child getChildAt(i);MarginLayoutParams params (MarginLayoutParams) child.getLayoutParams();//得到这一行的最高oldHeight maxLineHeight;//当前最大宽度oldWidth maxWidth;int deltaX child.getMeasuredWidth() params.leftMargin params.rightMargin;if (lineWidth deltaX getPaddingLeft() getPaddingRight() widthSize) {//如果折行,height增加//和目前最大的宽度比较,得到最宽。不能加上当前的child的宽,所以用的是oldWidthmaxWidth Math.max(lineWidth, oldWidth);//重置宽度lineWidth deltaX;//累加高度totalHeight oldHeight;//重置行高,当前这个View属于下一行因此当前最大行高为这个child的高度加上marginmaxLineHeight child.getMeasuredHeight() params.topMargin params.bottomMargin; // Log.v(TAG, maxHeight: totalHeight --- maxWidth: maxWidth);} else {//不换行累加宽度lineWidth deltaX;//不换行计算行最高int deltaY child.getMeasuredHeight() params.topMargin params.bottomMargin;maxLineHeight Math.max(maxLineHeight, deltaY);}if (i count - 1) {//前面没有加上下一行的搞如果是最后一行还要再叠加上最后一行的最高的值totalHeight maxLineHeight;//计算最后一行和前面的最宽的一行比较maxWidth Math.max(lineWidth, oldWidth);}}//加上当前容器的padding值maxWidth getPaddingLeft() getPaddingRight();totalHeight getPaddingTop() getPaddingBottom();setMeasuredDimension(widthMode MeasureSpec.EXACTLY ? widthSize : maxWidth,heightMode MeasureSpec.EXACTLY ? heightSize : totalHeight);}Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b) {int count getChildCount();//pre为前面所有的child的相加后的位置int preLeft getPaddingLeft();int preTop getPaddingTop();//记录每一行的最高值int maxHeight 0;for (int i 0; i count; i) {View child getChildAt(i);MarginLayoutParams params (MarginLayoutParams) child.getLayoutParams();//r-l为当前容器的宽度。如果子view的累积宽度大于容器宽度就换行。if (preLeft params.leftMargin child.getMeasuredWidth() params.rightMargin getPaddingRight() (r - l)) {//重置preLeft getPaddingLeft();//要选择child的height最大的作为设置preTop preTop maxHeight;maxHeight getChildAt(i).getMeasuredHeight() params.topMargin params.bottomMargin;} else { //不换行,计算最大高度maxHeight Math.max(maxHeight, child.getMeasuredHeight() params.topMargin params.bottomMargin);}//left坐标int left preLeft params.leftMargin;//top坐标int top preTop params.topMargin;int right left child.getMeasuredWidth();int bottom top child.getMeasuredHeight();//为子view布局child.layout(left, top, right, bottom);//计算布局结束后preLeft的值preLeft params.leftMargin child.getMeasuredWidth() params.rightMargin;}}}二、布局直接引用 LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalcsu.xiaoya.robotApp.ui.view.WrapRadioGroupandroid:idid/rg_blsandroid:layout_width438dpandroid:layout_height179dpandroid:layout_belowid/monitor_remdandroid:layout_alignParentRighttrueandroid:layout_marginTopdimen/dp_15android:layout_marginRightdimen/dp_24android:orientationhorizontalandroid:padding1dpapp:maxWidth300dpRadioButtonandroid:idid/rb_date_dayandroid:layout_widthdimen/dp_84android:layout_heightdimen/dimen_48android:backgrounddrawable/bls_am_2h_sgandroid:buttonnullandroid:checkedtrueandroid:layout_marginLeftdimen/dp_10android:gravitycenterandroid:text随机血糖android:textColorcolor/whiteandroid:textSizedimen/sp_10 /RadioButtonandroid:idid/rb_date_weekandroid:layout_widthdimen/dp_84android:layout_heightdimen/dimen_48android:layout_marginLeftdimen/dp_10android:backgrounddrawable/bls_am_2h_sgandroid:buttonnullandroid:gravitycenterandroid:text空腹血糖android:textColorcolor/whiteandroid:textSizedimen/sp_10 /RadioButtonandroid:layout_widthdimen/dp_84android:layout_heightdimen/dimen_48android:layout_marginLeftdimen/dp_10android:backgrounddrawable/bls_am_2h_sgandroid:buttonnullandroid:gravitycenterandroid:text早餐后2小时android:textColorcolor/whiteandroid:textSizedimen/sp_10 /RadioButtonandroid:layout_widthdimen/dp_84android:layout_heightdimen/dimen_48android:layout_marginLeftdimen/dp_10android:backgrounddrawable/bls_am_2h_sgandroid:buttonnullandroid:gravitycenterandroid:text早餐后2小时android:textColorcolor/whiteandroid:textSizedimen/sp_10 /RadioButtonandroid:layout_widthdimen/dp_84android:layout_heightdimen/dimen_48android:layout_marginLeftdimen/dp_10android:layout_marginTopdimen/dp_10android:backgrounddrawable/bls_am_2h_sgandroid:buttonnullandroid:gravitycenterandroid:text早餐后2小时android:textColorcolor/whiteandroid:textSizedimen/sp_10 //csu.xiaoya.robotApp.ui.view.WrapRadioGroup/LinearLayout 三、背景样式bls_am_2h_sg ?xml version1.0 encodingutf-8? selector xmlns:androidhttp://schemas.android.com/apk/res/androiditem android:width84dp android:height48dp android:state_checkedfalseshape android:shaperectanglesolid android:color#ff27b074 /corners android:bottomLeftRadius5dp android:bottomRightRadius5dp android:topLeftRadius5dp android:topRightRadius5dp //shape/itemitem android:width88dp android:height50dp android:state_checkedtrueshape android:shaperectanglesolid android:color#ff27b074 /corners android:bottomLeftRadius5dp android:bottomRightRadius5dp android:topLeftRadius5dp android:topRightRadius5dp //shape/item /selector 四、大功告成
http://www.dnsts.com.cn/news/126486.html

相关文章:

  • 徐州模板建站定制网站最好的自助建站系统
  • 建设购物网站费用关于网站的制作
  • 济南网站建设制作设计江门建设企业网站
  • 淮安涟水网站建设百度公司注册地址在哪里
  • 文登区城乡建设和规划局网站对外网站ipv6建设方案模板
  • 福州哪家企业网站建设设计最高端设计构建网站
  • 永康做网站的广西住房和城乡建设厅培训中心网
  • 网站建设管理员在线友情链接
  • 网站开发公司 logo网站的主页按钮怎么做
  • 企业网站群建设方案二级网站内容建设要求吗
  • 婚纱网站设计素材怎么自助建站
  • 网页建站素材模板visual composer wordpress.org
  • 做自媒体查找素材的网站服务公司荡神
  • 网吧网站怎么做的网站建设实验后体会
  • 网站备案拍照背景怎么用wordpress 建站
  • 成都网站优化推广方案网页设计和网站建设
  • 学校网站的建设论文一个网站服务器一年大概多少钱
  • 手机asp网站开发工具网站怎么设置二级域名
  • 广州网站建设一般多少钱比较好的做淘客网站
  • 搭建科技网站价格视频拍摄教程
  • 淄博网站制作首选专家凡科快图电脑版
  • 建站免费平台阿里云外贸建站
  • 集团网站定制文件夹里内容做网站的分类
  • 东莞企业网站推广宁波江北网站建设
  • 上海做家教去哪个网站网站广告psd
  • 汽车门户网站建设宝塔 wordpress
  • 做网站需要会语言吗东莞路桥投资发展有限公司
  • logopond设计网站做网站维护学什么编程语言
  • 手机网站案列十大外贸平台
  • 海南网站搭建2022年新项目加盟代理