日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 嵌入式 > 嵌入式軟件
[導(dǎo)讀] 最近使用tabhost,有一些新的,遂寫在下面:tabhost的使用有一些固定的格式,首先要求在布局文件的格式為tabhost標(biāo)簽里面添加framelayout,在里面添加相應(yīng)的控件,至少包括

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

tabhost的使用有一些固定的格式,首先要求在布局文件的格式為tabhost標(biāo)簽里面添加framelayout,在里面添加相應(yīng)的控件,至少包括一個(gè)framelayout和tabwidget,framelayout必須命名為@android:id/tabcontent,tabwidget必須命名為@android:id/tabs,這里,tabcontent里面存放的是加載的多個(gè)activity,tabs里面存放的是與各個(gè)activity相對應(yīng)的下面的按鈕,這里需要注意的是,我剛開始的時(shí)候布局文件設(shè)定完畢,tabs就是顯示不出來,最后發(fā)現(xiàn)需要在tabcontent里面設(shè)置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">

 

 

 

 

之后就只需要在對應(yīng)的activity里面添加相應(yīng)的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的唯一標(biāo)示,setIndicator設(shè)置的是tabs上現(xiàn)實(shí)的文字,setContent是顯示的activity。

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

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

同時(shí)view切換的時(shí)候也可以添加適當(dāng)?shù)膭?dòng)畫效果:

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)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉