@Override
protected voidonMeasure(intwidthMeasureSpec,intheightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
intchildCount = getChildCount();
intsizeWidth = MeasureSpec.getSize(widthMeasureSpec);
floatleft =0.0f,right=0.0f,top=0.0f,bottom=0.0f;
intlines = sizeWidth;
View view;
intchildWidth;
intlineItems =0;
Position position ;
for(inti=0; i < childCount ; i++){
view = getChildAt(i);
measureChild(view,widthMeasureSpec,heightMeasureSpec);
childWidth = view.getMeasuredWidth() ;
if(lines - childWidth >=mPadding){
if(right ==0){
lines -= childWidth;
right =1;
}else{
lines -= (childWidth +mPadding);
}
lineItems ++;
if(i == childCount-1){
right =0;
for(intj = i - lineItems +1;j <= i;j++){
if(right ==0){
left = right;
}else{
left = right +mPadding;
}
right = left + getChildAt(j).getMeasuredWidth();
bottom = top + getChildAt(j).getMeasuredHeight();
position =newPosition(left,top,right,bottom);
getChildAt(j).setPadding(10,5,10,5);
getChildAt(j).setTag(position);
}
}
}else{
right =0;
floatlinesPadding = lines / (2* lineItems);
for(intj = i - lineItems; j < i ;j++){
if(right ==0){
left = right;
}else{
left = right +mPadding;
}
right = left + getChildAt(j).getMeasuredWidth() +2* linesPadding;
bottom = top + getChildAt(j).getMeasuredHeight();
position =newPosition(left,top,right,bottom);
getChildAt(j).setPadding((int)linesPadding,5,(int)linesPadding,5);
getChildAt(j).setTag(position);
}
lines = sizeWidth;
right =0;
top = bottom +10;
lineItems =0;
i--;
}
}
setMeasuredDimension(sizeWidth, (int) bottom);
}
自定義view仿bilibili的自適應(yīng)tag
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 「博客搬家」 原地址: CSDN 原發(fā)表時(shí)間: 2016-10-12 本文主要總結(jié)使用 C# 及 .NET 在...
- 【日精進(jìn)打卡第31天】 【知~學(xué)習(xí)】 《六項(xiàng)精進(jìn)》2遍共62遍 《大學(xué)》2遍共62遍 【經(jīng)典名句分享】 付出不亞于...
- ▎斗筆爭鋒 下面錄幾則武俠宗師斗筆爭鋒的掌故,拾人齒間牙慧菜葉,附會(huì)成章,但不敷衍。 溫瑞安八十代因故離開臺(tái)灣,香...