本文主要介绍自动换行linearlayout,下面一起看看自动换行linearlayout相关资讯。
转:(22条消息)radiogroup的博客带自动换行点击事件_再见美猴王_ -csdn博客。
公共类myradiogroup扩展了radio group { private static final string tag = radiogroupex public my radio group(context context){ super(context);} public my radio group(context context,attributeset attrs){ super(context,attrs);} @ override protected void on measure(int widthmeasurespec,int heightsmeasurespec){ int width size = measurespec . getsize(widthmeasurespec);int width mode = measure spec . get mode(widthmeasurespec);int heightsize = measure spec . getsize(heightsmeasurespec);int height mode = measure spec . get mode(heightmaurespec);//调用viewgroup的方法来度量视图measure children(width measure spec,heightmeasurespec);//最大宽度int maxwidth = 0;//累计高度int total height = 0;//当前行的累计线宽int line width = 0;//当前行的最大行高int maxline height = 0;//用于记录换行前的线宽和行高int oldheightint旧宽度;int count = get child count;//假设widthmode和heightmode都是_ most for(int i = 0;我数;i){ view child = get child at(i);边缘layout params params =(marginlayoutparams)child . getlayout params;//获取该行的最高oldheight = maxlineheight//当前最大宽度oldwidth = maxwidthint deltax = child . getmeasuredwidthparams . left margin params . right margin;if(line width deltax getpadding lightgetpadding lightwidth size){//如果换行,高度增加//与当前最大宽度相比,获得最宽宽度。你可以 t加上当前子的宽度,所以你用宽度maxwidth = math.max (line width,width);//reset width line width = deltax;//累积高度totalheight = oldheight//重置行高。当前视图属于下一行,因此当前最大行高是该子级的高度加上marginmax line height = child。getmeasureheight参数。上边距参数。底部边距;log.v(标签, maxheightcho 0-@ . com 总高度 - maxwidth: maxwidth);} else {//不换行,累计宽度linewidth = deltax//不换行,计算最高int deltay = child . getmeasureheightparams . top margin params . bottom margin;maxline height = math . max(maxline height,deltay);} if (i == count-1) {//在它之前不添加下一行。如果是最后一行,必须叠加最后一行的最高值:totalheight = maxlineheight//将计算的最后一行与其前面最宽的一行进行比较maxwidth = math.max(线宽,旧宽度);} }//加上当前容器的填充值maxwidth = getpadding lightgetpadding light;total height = getpadding topgetpadding bottom;setmeasureddimension(width mode = = measure spec。确实如此。宽度尺寸:最大宽度,高度模式==测量规格。确实如此。h:总高度);} @ override protected void onlayout(boolean changed,int l,int t,int r,int b){ int count = get child count;//pre是所有前一个子元素的添加位置。int pre left = getpadding left;int pretop = getpadding top;//记录每行的最高值int max height = 0;for(int i = 0;我数;i){ view child = get child at(i);marginlayoutparams params =(marginlayoutparams)child . getlayoutparams;//r-l是当前容器的宽度。如果子视图的累积宽度大于容器宽度,则换行。if(前置左参数。左边距子对象。getmeasurewidth参数。右边距getpadding light(r-l)){//reset pre left = getpadding left;//选择身高最大的孩子作为设置pretop = pretop maxheightmaxheight = getchildat(i)。getmeasuredheightparams . top margin params . bottom margin;} else {//不换行,计算最大高度max height = math.max (max height,child。getmeasureheight参数。上边距参数。下边距);}//左坐标intleft = prelefparams。左边距;//top coordinate int top = pretop params . top margin;int right = left child . getmeasuredwidth;int bottom = top child . getmeasuredheight;//子视图的layout child.layout (left,top,right,bottom);//计算布局后,preleft = params的值。leftmarginchild。getmeasurewidth参数。右边距;}}}标签:
宽度包装
了解更多自动换行linearlayout相关内容请关注本站点。