<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > android TabHost的使用介紹

android TabHost的使用介紹

作者: 時(shí)間:2016-09-12 來(lái)源:網(wǎng)絡(luò ) 收藏

最近使用tabhost,有一些新的,遂寫(xiě)在下面:

本文引用地址:http://dyxdggzs.com/article/201609/305044.htm

tabhost的使用有一些固定的格式,首先要求在布局文件的格式為tabhost標簽里面添加framelayout,在里面添加相應的控件,至少包括一個(gè)framelayout和tabwidget,framelayout必須命名為@android:id/tabcontent,tabwidget必須命名為@android:id/tabs,這里,tabcontent里面存放的是加載的多個(gè)activity,tabs里面存放的是與各個(gè)activity相對應的下面的按鈕,這里需要注意的是,我剛開(kāi)始的時(shí)候布局文件設定完畢,tabs就是顯示不出來(lái),最后發(fā)現需要在tabcontent里面設置android:layout_weight=1之后就可以了,不知道是什么原因,有大神知道請告知小弟。

android:layout_width=match_parent

android:layout_height=match_parent

android:id=@android:id/tabhost>

android:layout_width=fill_parent

android:layout_height=fill_parent>

android:layout_width=fill_parent

android:layout_height=fill_parent

android:orientation=vertical

>

android:layout_width=fill_parent

android:layout_height=fill_parent

android:id=@android:id/tabcontent

android:background=#fff00000

android:layout_weight=1>

android:id=@+id/tvTabShpw

android:layout_width=fill_parent

android:layout_height=wrap_content

android:text=textviewshow

android:layout_gravity=bottom

android:gravity=center/>

android:layout_width=fill_parent

android:layout_height=wrap_content

android:id=@android:id/tabs

android:visibility=gone>

之后就只需要在對應的activity里面添加相應的activity就行了

tabhost = this.getTabHost();

tabhost.addTab(tabhost.newTabSpec(INDEX_HOME)

.setIndicator(INDEX_HOME)

.setContent(new Intent(this, NewHomeActivity.class)));

tabhost.addTab(tabhost.newTabSpec(INDEX_MESSAGE)

.setIndicator(INDEX_MESSAGE).setContent(new Intent(this,MessageActivityNew.class)));

tabhost.addTab(tabhost.newTabSpec(INDEX_PROFILE).setIndicator(INDEX_PROFILE)

.setContent(new Intent(this, SelfProfileActivity.class)));

tabhost.addTab(tabhost.newTabSpec(INDEX_SQUARE).setIndicator(INDEX_SQUARE)

.setContent(new Intent(this, SquareActivityNew.class)));

其中INDEX_SQUARE為activity的唯一標示,setIndicator設置的是tabs上現實(shí)的文字,setContent是顯示的activity。

然后通過(guò)點(diǎn)擊下面的tabs或者通過(guò)tabhost.setCurrentTab(0);來(lái)切換view。

同時(shí)setIndicator里面除了添加字符串,也可以添加view,美化一下。但是一般這樣還是不夠美觀(guān),所以我就自定義了一個(gè)view蓋住tabs,通過(guò)點(diǎn)擊里面的事件出發(fā)tabhost.setCurrentTab(0);來(lái)切換view。

同時(shí)view切換的時(shí)候也可以添加適當的動(dòng)畫(huà)效果:

Animation inAnim = null, outAnim = null;

if (tabhost.getCurrentTab() itemPos) {

outAnim = AnimationUtils

.loadAnimation(MainActivity.this,

R.anim.push_left_out);

inAnim = AnimationUtils.loadAnimation(

MainActivity.this, R.anim.push_left_in);

tabhost.getCurrentView().startAnimation(

outAnim);

tabhost.setCurrentTab(itemPos);

tabhost.getCurrentView()

.startAnimation(inAnim);

} else if (tabhost.getCurrentTab() > itemPos) {

outAnim = AnimationUtils.loadAnimation(

MainActivity.this,

R.anim.push_right_out);

inAnim = AnimationUtils

.loadAnimation(MainActivity.this,

R.anim.push_right_in);

tabhost.getCurrentView().startAnimation(

outAnim);

tabhost.setCurrentTab(itemPos);

tabhost.getCurrentView()

.startAnimation(inAnim);

} else {

tabhost.setCurrentTab(itemPos);

}



關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>