android 換行亂 Android自動換行布局

2021-10-22 19:12:19 字數 2054 閱讀 2022

public class flowlayout extends viewgroup else else {

//不需要換行的情況

linecountwidth += childwidth;

//取當前行的所有子控制項最大的高度

linemaxheight = math.max(linemaxheight, childheight);

viewlist.add(childview);

//這樣做的原因是 之前的if else中 不會把最後一行的高度加進listlineheight

// 最後一行要特殊對待 不管最後乙個item是不是最後一行的第乙個item

if (i == (childcount - 1)) {

//儲存當前行資訊

childmaxwidth = math.max(childmaxwidth, linecountwidth + getpaddingleft() + getpaddingright());

childcountheight += linemaxheight;

lineheightlist.add(linemaxheight);

linelist.add(viewlist);

//設定控制項最終大小

int measurewidth = (widthmode == measurespec.exactly ? widthsize : childmaxwidth + getpaddingleft() + getpaddingright());

int measureheight = (heightmode == measurespec.exactly ? heightsize : childcountheight + getpaddingtop() + getpaddingbottom());

setmeasureddimension(measurewidth, measureheight);

@override

protected void onlayout(boolean changed, int l, int t, int r, int b) {

//擺放子控制項的位置

int left, top, right, bottom;

//儲存上乙個控制項的邊距

int countleft = 0;

//儲存上一行的高度的邊距

int counttop = 0;

//遍歷所有行

for (list views : linelist) {

//遍歷每一行的控制項

for (view view : views) {

marginlayoutparams layoutparams = (marginlayoutparams) view.getlayoutparams();

left = countleft + layoutparams.leftmargin;

top = counttop + layoutparams.topmargin;

right = left + view.getmeasuredwidth();

bottom = top + view.getmeasuredheight();

view.layout(left + getpaddingleft(), top + getpaddingtop(), right + getpaddingright(), bottom + getpaddingbottom());

//記錄當前控制項的實際寬度座標,讓下乙個控制項知道x軸的起點在哪

countleft += view.getmeasuredwidth() + layoutparams.leftmargin + layoutparams.rightmargin;

int i = linelist.indexof(views);

//換行時從最左邊開始

countleft = 0;

//換行時累加高度

counttop += lineheightlist.get(i);

//布局結束後清空記錄的list

linelist.clear();

lineheightlist.clear();

Android的開發之 無線除錯android裝置

這段時間一直在忙啊忙,公司要做機頂盒,沒有人做過,無奈之下只能邊研究邊做,經過乙個多月的時間,測試版本終於出來了。今天給大家介紹下使用adb命令無線除錯除錯安卓應用,那有些人肯定會問,無線除錯有啥用啊,連著線除錯挺好的。那如果線壞了那,你會說在換乙個,那如果電腦usb插口壞了那,當然可以換個電腦,哈...

Android中TextView自動換行問題

今天忽然發現android專案中的文字排版參差不齊的情況非常嚴重,不得不想辦法解決一下。經過研究之後,終於找到了textview自動換行導致混亂的原因了 半形字元與全形字符混亂所致!一般情況下,我們輸入的數字 字母以及英文標點都是半形,所以佔位無法確定。它們與漢字的佔位大大的不同,由於這個原因,導致...

Android 監聽enter鍵 換行新增標籤

mactivitymembermanagementaddedit2.sethorizontallyscrolling false mactivitymembermanagementaddedit2.setmaxlines integer.max value mactivitymembermanage...