国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android仿新浪微博分頁管理界面(3)

2019-12-12 04:34:14
字體:
供稿:網(wǎng)友

本文實例為大家分享了Android仿新浪微博分頁管理界面的具體代碼,供大家參考,具體內(nèi)容如下

多個activity分頁管理,為了方便獲取上下文,采用繼承TabActivity的傳統(tǒng)方法。

大致思路:使用RadioGroup點擊觸發(fā)不同的選卡項,選卡項綁定不同的activiity,進(jìn)而進(jìn)行分頁管理。詳解見注解。

/** * 主Activity * 通過點擊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() {  //實例化TabHost,得到TabHost對象  tabHost = getTabHost();  //得到Activity的個數(shù)  int count = Constant.ConValue.mTabClassArray.length;  for (int i = 0; i < count; i++) {   //為每一個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選項卡中   tabHost.addTab(tabSpec);  }  //實例化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選項卡設(shè)置內(nèi)容(每個內(nèi)容都是一個Activity)  */ private Intent getTabItemIntent(int index) {  Intent intent = new Intent(this, Constant.ConValue.mTabClassArray[index]);  return intent; }}

MainActivity布局文件tab_layout.xml. TabHost布局,添加一個TabWidget用于顯示activity,下面是一個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í)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 潮州市| 巩留县| 稻城县| 田林县| 延安市| 抚州市| 界首市| 忻州市| 乐业县| 凉山| 朝阳县| 泌阳县| 阳山县| 泰安市| 隆林| 崇文区| 沛县| 顺平县| 习水县| 武鸣县| 瓦房店市| 随州市| 筠连县| 望江县| 土默特右旗| 临沂市| 仙桃市| 九寨沟县| 鲜城| 仙居县| 洛川县| 绥中县| 榆树市| 航空| 奇台县| 洱源县| 厦门市| 邹平县| 东港市| 封丘县| 来凤县|