只貼出了核心**,具體請檢視我的github,記得點顆✨哦!
1. 實現底部的tab,自定義tabcontainerview 繼承 relativelayout,這是我們最終封裝的view工具類。其內部主要由viewpager和底部的tabhost類組成。
viewpager初始化
contentviewpager = new viewpager(context);
layoutparams contentvplp = new layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent);
contentvplp.addrule(relativelayout.above, r.id.divide_tab);
contentviewpager.setlayoutparams(contentvplp);
contentviewpager.setid(r.id.viewpager_tab);
contentviewpager.addonpagechangelistener(new viewpager.onpagechangelistener()
@override
public
void
onpageselected
(int position)
@override
public
void
onpagescrollstatechanged
(int state)
});addview(contentviewpager);
底部tab是乙個自定義的橫向布局linearlayout,動態新增多個寬度等分的tab按鈕
for (int i = 0; i < count; i++)
tab tab = new tab(context, textarray[i], textsize, textcolor, selectedtextcolor,drawablepadding,iconwidth,iconheight, iconimagearray[i], selectediconimagearray[i], i,hasmsg);
addtab(tab);
}
tab按鈕的實現
rootview = new linearlayout(context);
childview=new relativelayout(context);
linearlayout.layoutparams rootviewlp = new linearlayout.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.wrap_content);
rootviewlp.weight = 1;
rootview.setorientation(linearlayout.vertical);
rootview.setpadding(0,20,0,20);
rootview.setlayoutparams(rootviewlp);
texttextview = new textview(context);
iconimageview = new imageview(context);
/*** icon view
*/iconimageview.setimageresource(iconimage);
relativelayout.layoutparams iconparam=new relativelayout.layoutparams(iconwidth==0? viewgroup.layoutparams.wrap_content:iconwidth,iconheight==0? viewgroup.layoutparams.wrap_content:iconheight);
iconparam.addrule(relativelayout.center_horizontal);
iconimageview.setlayoutparams(iconparam);
iconimageview.setid(index+1);
childview.addview(iconimageview);
/*** text view
*/texttextview.settext(text);
texttextview.settextcolor(textcolor);
texttextview.settextsize(typedvalue.complex_unit_px,textsize);
texttextview.setpadding(0,drawablepadding,0,0);
relativelayout.layoutparams txparam=new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content);
txparam.addrule(relativelayout.below,childview.getchildat(0).getid());
txparam.addrule(relativelayout.center_horizontal);
texttextview.setlayoutparams(txparam);
childview.addview(texttextview);
if(hasmsg)
relativelayout.layoutparams childparam=new relativelayout.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent);
childview.setlayoutparams(childparam);
rootview.addview(childview);
android:id="@+id/tab_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tabcontainerview tabcontainerview = (tabcontainerview) findviewbyid(r.id.tab_container);
mainviewadapter mainviewadapter=new mainviewadapter(getsupportfragmentmanager(),
new fragment );
mainviewadapter.sethasmsgindex(5);
tabcontainerview.setadapter(mainviewadapter);
tabcontainerview.setontabselectedlistener(new ontabselectedlistener()
});
tabtextsize:導航按鈕字型大小
iconheight: 導航圖示高度
iconwidth:導航圖示寬度
dividelinecolor:導航欄頂部分割線顏色
dividelineheight:導航欄頂部分割線高度
sethasmsgindex(5); //第五個導航按鈕有訊息提醒
CSS例項 四 實現TabView 頁籤 效果
今天花了點時間,設計了乙個網頁上用的tabview 頁籤 tabcontrol 效果。個人覺得實現得比較不錯,網頁元素用得比較少,js 也比較精練。測試了一下支援ie firefox以及chrome。支援同一頁面上多處使用。沒有什麼過多說的。先看一下效果。頁面中用到乙個 align center i...
快速排序實現
1.結束條件 low high 2.快速排序要分而治之。故需要分的位置,位置便是當前元素經過排列後應該所在的位置。3.對於單次的排列,都使得乙個元素排在了正確的位置,她的左面比她小,右側比她大。package com.jue.quicksort public class quicksort logs...
實現 快速排序
快速排序的基本思想 1 先從數列中選擇乙個數作為基準數 一般會把陣列中最左邊的數當做基準數 2 然後從數列兩邊進行檢索 先從右邊檢索比基準數小的,再從左邊檢索比基準數大的 如果檢索到了,就停下,然後交換這兩個元素。然後再繼續檢索。3 直到左檢索和右檢索相遇,把基準數和相遇位置的數交換。4 第一輪檢索...