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

首頁 > 系統 > Android > 正文

Android Fragment+FragmentTabHost組件實現常見主頁面(仿微信新浪)

2019-12-12 05:19:46
字體:
來源:轉載
供稿:網友

采取的方法是Fragment+FragmentTabHost組件來實現這種常見的app主頁面的效果

首先給出main.xml文件

  <?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical" android:layout_width="match_parent"  android:layout_height="match_parent">  <FrameLayout   android:id="@+id/realtabcontent"   android:layout_width="fill_parent"   android:layout_height="0dip"   android:layout_weight="1"   android:background="@color/white" />    <LinearLayout   android:layout_width="match_parent"  android:layout_height="wrap_content"   android:layout_gravity="bottom"   android:orientation="vertical">    <View    android:layout_width="match_parent"    android:layout_height="1px"    android:background="@color/color_home_tab_line" />    <android.support.v4.app.FragmentTabHost    android:id="@android:id/tabhost"  android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:background="@color/et_divider_disable">     <FrameLayout     android:id="@android:id/tabcontent"    android:layout_width="0dp"     android:layout_height="0dp"     android:layout_weight="0" />   </android.support.v4.app.FragmentTabHost>    </LinearLayout>  </LinearLayout>

主代碼:

 public class MainActivity { @ViewInject(android.R.id.tabhost)   private FragmentTabHost mTabHost; private LayoutInflater layoutInflater;  private int mImageViewArray[] = {R.drawable.home_tab1, R.drawable.home_tab2, R.drawable.home_tab3, R.drawable.home_tab4};   private String mTextviewArray[] = {"首頁", "圈子", "資訊","個人中心"};   private Class fragmentArray[] = {Fragment1.class, Fragment2.class, Fragment3.class,Fragment4.class};  protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     init();   }  @Override   protected void init() { //    list=new JSONArray();     layoutInflater=LayoutInflater.from(this);     initTabHost();//初始化底部菜單 }  /**   * 初始化底部工具欄   */   private void initTabHost() {     mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);     mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);     int count = fragmentArray.length;     for (int i = 0; i < count; i++) {       TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i])           .setIndicator(getTabItemView(i));       mTabHost.addTab(tabSpec, fragmentArray[i], null);       mTabHost.getTabWidget().getChildAt(i)           .setBackgroundResource(R.color.white);     }     mTabHost.setCurrentTabByTag(mTextviewArray[0]);     mTabHost.getTabWidget().setDividerDrawable(null); }   /**   * 項的樣式   * @param index 第幾個   * @return 每一個Tab樣式   */   private View getTabItemView(int index) {     View view = layoutInflater.inflate(R.layout.tab_home_item, null);     ImageView imageView = (ImageView) view.findViewById(R.id.icon);     imageView.setImageResource(mImageViewArray[index]);     TextView textView = (TextView) view.findViewById(R.id.name);     textView.setText(mTextviewArray[index]);     return view;   }     }

通過以上文章,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 观塘区| 罗田县| 萨迦县| 乐昌市| 横峰县| 南华县| 安福县| 东安县| 潍坊市| 乌什县| 喜德县| 民权县| 吉安县| 沅江市| 南召县| 青田县| 革吉县| 米脂县| 华阴市| 温州市| 肥乡县| 江陵县| 武隆县| 深圳市| 拉萨市| 浦东新区| 宜宾县| 易门县| 丰都县| 横峰县| 山阳县| 天柱县| 宁河县| 宕昌县| 唐河县| 淳化县| 格尔木市| 龙门县| 澄迈县| 杂多县| 会昌县|