Android仿新浪微博分頁管理界面(3)
本文實(shí)例為大家分享了Android仿新浪微博分頁管理界面的具體代碼,供大家參考,具體內(nèi)容如下
多個(gè)activity分頁管理,為了方便獲取上下文,采用繼承TabActivity的傳統(tǒng)方法。
大致思路:使用RadioGroup點(diǎn)擊觸發(fā)不同的選卡項(xiàng),選卡項(xiàng)綁定不同的activiity,進(jìn)而進(jìn)行分頁管理。詳解見注解。
/**
* 主Activity
* 通過點(diǎn)擊RadioGroup下的RadioButton來切換不同界面
* Created by D&LL on 2016/7/20.
*/
public class MainActivity extends TabActivity {
//定義TabHost對象
private TabHost tabHost;
//定義RadioGroup對象
private RadioGroup radioGroup;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_layout);
initView();
initData();
}
/**
* 初始化組件
*/
private void initView() {
//實(shí)例化TabHost,得到TabHost對象
tabHost = getTabHost();
//得到Activity的個(gè)數(shù)
int count = Constant.ConValue.mTabClassArray.length;
for (int i = 0; i < count; i++) {
//為每一個(gè)Tab按鈕設(shè)置圖標(biāo)、文字和內(nèi)容
TabSpec tabSpec = tabHost.newTabSpec(Constant.ConValue.mTextviewArray[i])
.setIndicator(Constant.ConValue.mTextviewArray[i]).setContent(getTabItemIntent(i));
//將Tab按鈕添加進(jìn)Tab選項(xiàng)卡中
tabHost.addTab(tabSpec);
}
//實(shí)例化RadioGroup
radioGroup = (RadioGroup) findViewById(R.id.main_radiogroup);
}
/**
* 初始化組件
*/
private void initData() {
// 給radioGroup設(shè)置監(jiān)聽事件
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.RadioButton0:
tabHost.setCurrentTabByTag(Constant.ConValue.mTextviewArray[0]);
break;
case R.id.RadioButton1:
tabHost.setCurrentTabByTag(Constant.ConValue.mTextviewArray[1]);
break;
case R.id.RadioButton2:
tabHost.setCurrentTabByTag(Constant.ConValue.mTextviewArray[2]);
break;
case R.id.RadioButton3:
tabHost.setCurrentTabByTag(Constant.ConValue.mTextviewArray[3]);
break;
case R.id.RadioButton4:
tabHost.setCurrentTabByTag(Constant.ConValue.mTextviewArray[4]);
break;
}
}
});
((RadioButton) radioGroup.getChildAt(0)).toggle();
}
/**
* 給Tab選項(xiàng)卡設(shè)置內(nèi)容(每個(gè)內(nèi)容都是一個(gè)Activity)
*/
private Intent getTabItemIntent(int index) {
Intent intent = new Intent(this, Constant.ConValue.mTabClassArray[index]);
return intent;
}
}
MainActivity布局文件tab_layout.xml. TabHost布局,添加一個(gè)TabWidget用于顯示activity,下面是一個(gè)RadioGroup顯示切換activity的按鈕菜單。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:visibility="gone"/>
<RadioGroup
android:id="@+id/main_radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/tab_widget_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="2dip">
<RadioButton
android:id="@+id/RadioButton0"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_home"
android:text="主頁"
android:textColor="#ffffff"/>
<RadioButton
android:id="@+id/RadioButton1"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_msg"
android:text="評論"
android:textColor="#ffffff"/>
<RadioButton
android:id="@+id/RadioButton2"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_write"
android:text="發(fā)微博"
android:textColor="#ffffff"/>
<RadioButton
android:id="@+id/RadioButton3"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_me"
android:text="用戶信息"
android:textColor="#ffffff"/>
<RadioButton
android:id="@+id/RadioButton4"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_more"
android:text="更多"
android:textColor="#ffffff"/>
</RadioGroup>
</LinearLayout>
</TabHost>
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android仿新浪微博發(fā)布微博界面設(shè)計(jì)(5)
- Android仿新浪微博自定義ListView下拉刷新(4)
- Android仿新浪微博oauth2.0授權(quán)界面實(shí)現(xiàn)代碼(2)
- Android仿新浪微博啟動(dòng)界面或登陸界面(1)
- Android用PopupWindow實(shí)現(xiàn)新浪微博的分組信息實(shí)例
- Android仿新浪微博、QQ空間等帖子顯示(2)
- Android仿新浪微博、QQ空間等帖子顯示(1)
- Android仿新浪微博/QQ空間滑動(dòng)自動(dòng)播放視頻功能
- Android集成新浪微博第三方登錄的方法
- Android仿新浪微博個(gè)人信息界面及其他效果
相關(guān)文章
Android7.0 MTK設(shè)置默認(rèn)桌面
這篇文章主要為大家詳細(xì)介紹了Android7.0 MTK設(shè)置默認(rèn)桌面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
Android Studio 中的Gradle構(gòu)建系統(tǒng)示例
這篇文章主要介紹了Android Studio 中的Gradle構(gòu)建系統(tǒng)示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11
Android開發(fā)學(xué)習(xí)筆記之通過API接口將LaTex數(shù)學(xué)函數(shù)表達(dá)式轉(zhuǎn)化為圖片形式
這篇文章主要介紹了Android開發(fā)學(xué)習(xí)筆記之通過API接口將LaTex數(shù)學(xué)函數(shù)表達(dá)式轉(zhuǎn)化為圖片形式的相關(guān)資料,需要的朋友可以參考下2015-11-11
Android編程實(shí)現(xiàn)小說閱讀器滑動(dòng)效果的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)小說閱讀器滑動(dòng)效果的方法,涉及onTouch事件滑動(dòng)效果的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Android編程之匿名內(nèi)部類與回調(diào)函數(shù)用法分析
這篇文章主要介紹了Android編程之匿名內(nèi)部類與回調(diào)函數(shù)用法,結(jié)合實(shí)例形式分析了Android編程中所涉及的java匿名內(nèi)部類與回調(diào)函數(shù)的概念、定義、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-10-10
Android 設(shè)置應(yīng)用全屏的兩種解決方法
本篇文章小編為大家介紹,Android 設(shè)置應(yīng)用全屏的兩種解決方法。需要的朋友參考下2013-04-04
Android自定義View實(shí)現(xiàn)豎直跑馬燈效果案例解析
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)豎直跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
Android 自定義View結(jié)合自定義TabLayout實(shí)現(xiàn)頂部標(biāo)簽滑動(dòng)效果
小編最近在做app的項(xiàng)目,需要用到tablayout實(shí)現(xiàn)頂部的滑動(dòng)效果,文中代碼用到了自定義item,代碼也很簡單,感興趣的朋友跟隨腳本之家小編一起看看吧2018-07-07

