本文主要介紹自動(dòng)換行l(wèi)inearlayout,下面一起看看自動(dòng)換行l(wèi)inearlayout相關(guān)資訊。
轉(zhuǎn):(22條消息)radiogroup的博客帶自動(dòng)換行點(diǎn)擊事件_再見美猴王_ -csdn博客。
公共類myradiogroup擴(kuò)展了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);//調(diào)用viewgroup的方法來度量視圖measure children(width measure spec,heightmeasurespec);//最大寬度int maxwidth = 0;//累計(jì)高度int total height = 0;//當(dāng)前行的累計(jì)線寬int line width = 0;//當(dāng)前行的最大行高int maxline height = 0;//用于記錄換行前的線寬和行高int oldheightint舊寬度;int count = get child count;//假設(shè)widthmode和heightmode都是_ most for(int i = 0;我數(shù);i){ view child = get child at(i);邊緣layout params params =(marginlayoutparams)child . getlayout params;//獲取該行的最高oldheight = maxlineheight//當(dāng)前最大寬度oldwidth = maxwidthint deltax = child . getmeasuredwidthparams . left margin params . right margin;if(line width deltax getpadding lightgetpadding lightwidth size){//如果換行,高度增加//與當(dāng)前最大寬度相比,獲得最寬寬度。你可以 t加上當(dāng)前子的寬度,所以你用寬度maxwidth = math.max (line width,width);//reset width line width = deltax;//累積高度totalheight = oldheight//重置行高。當(dāng)前視圖屬于下一行,因此當(dāng)前最大行高是該子級的高度加上marginmax line height = child。getmeasureheight參數(shù)。上邊距參數(shù)。底部邊距;log.v(標(biāo)簽, maxheightcho 0-@ . com 總高度 - maxwidth: maxwidth);} else {//不換行,累計(jì)寬度linewidth = deltax//不換行,計(jì)算最高int deltay = child . getmeasureheightparams . top margin params . bottom margin;maxline height = math . max(maxline height,deltay);} if (i == count-1) {//在它之前不添加下一行。如果是最后一行,必須疊加最后一行的最高值:totalheight = maxlineheight//將計(jì)算的最后一行與其前面最寬的一行進(jìn)行比較maxwidth = math.max(線寬,舊寬度);} }//加上當(dāng)前容器的填充值maxwidth = getpadding lightgetpadding light;total height = getpadding topgetpadding bottom;setmeasureddimension(width mode = = measure spec。確實(shí)如此。寬度尺寸:最大寬度,高度模式==測量規(guī)格。確實(shí)如此。h:總高度);} @ override protected void onlayout(boolean changed,int l,int t,int r,int b){ int count = get child count;//pre是所有前一個(gè)子元素的添加位置。int pre left = getpadding left;int pretop = getpadding top;//記錄每行的最高值int max height = 0;for(int i = 0;我數(shù);i){ view child = get child at(i);marginlayoutparams params =(marginlayoutparams)child . getlayoutparams;//r-l是當(dāng)前容器的寬度。如果子視圖的累積寬度大于容器寬度,則換行。if(前置左參數(shù)。左邊距子對象。getmeasurewidth參數(shù)。右邊距getpadding light(r-l)){//reset pre left = getpadding left;//選擇身高最大的孩子作為設(shè)置pretop = pretop maxheightmaxheight = getchildat(i)。getmeasuredheightparams . top margin params . bottom margin;} else {//不換行,計(jì)算最大高度max height = math.max (max height,child。getmeasureheight參數(shù)。上邊距參數(shù)。下邊距);}//左坐標(biāo)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);//計(jì)算布局后,preleft = params的值。leftmarginchild。getmeasurewidth參數(shù)。右邊距;}}}標(biāo)簽:
寬度包裝
了解更多自動(dòng)換行l(wèi)inearlayout相關(guān)內(nèi)容請關(guān)注本站點(diǎn)。
三星固態(tài)sn碼編碼規(guī)則
電芯對身體的傷害(電芯容易壞嗎)
插上u盤顯示格式化怎么修復(fù),U盤插入電腦打開提示需要格式化怎么恢復(fù)數(shù)據(jù)
ryzen53600相當(dāng)于英特爾的哪個(gè)(ryzen 5 3600相當(dāng)于)
電腦硬盤接線方法圖,固態(tài)硬盤怎么接線
自動(dòng)換行l(wèi)inearlayout
微信訂閱號消息為什么不按時(shí)間排序發(fā)送(為什么微信訂閱號消息不按時(shí)間順序)
蘋果系統(tǒng)更新以后還能換回以前的嗎(蘋果系統(tǒng)更新能不能換回去)
如何安裝win10鏡像(怎么直接安裝w10鏡像系統(tǒng))
游戲盒子推薦軟件(游戲盒app推薦)
電腦u盤啟動(dòng)盤有什么作用嗎(電腦u盤啟動(dòng)盤是什么盤)
手機(jī)變磚怎么辦,我手機(jī)變磚了怎么辦
云閃付轉(zhuǎn)賬失敗退款嗎安全嗎(云閃付轉(zhuǎn)賬失敗錢一直沒退回來怎么辦)
戴爾11代cpu裝win7(戴爾11代筆記本怎么裝系統(tǒng))
蘋果內(nèi)存灰色怎么刪除掉(蘋果內(nèi)存灰色怎么刪除不了)
酷派大神f1怎么關(guān)閉瀑布流,瀑布流關(guān)不掉
美版s版 怎么樣,美版iphone怎么樣
鍵盤被鎖打不了字(電腦鍵盤鎖住了打不了字怎么解鎖)
bp程序是什么(bp程序全稱)
萬維的3d顯示屏怎么樣,海爾LE50A900K 使用什么3D眼鏡