乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Android TabHost 標(biāo)簽放在底部+Header

       昵稱8269077 2012-03-23

      轉(zhuǎn)載請注明:http://www.cnblogs.com/soloho/archive/2012/03/17/2403232.html

      附件下載鏈接:api.zip

      網(wǎng)上已經(jīng)有很多關(guān)于如何將TabHost的標(biāo)簽放在底部,這里就不說了

      主要是把這些都做成框架,只需要提供圖片和文字就可以實現(xiàn)這樣的效果。

      直接上圖,代碼解釋的很清楚

      程序的圖片借用新浪微博,如有不妥,請告知



      代碼:

      package com.api.example.app;


      import java.util.ArrayList;

      import java.util.List;


      import android.content.Intent;

      import android.os.Bundle;

      import android.view.LayoutInflater;

      import android.view.View;

      import android.widget.TabWidget;

      import android.widget.TextView;


      import com.api.R;

      import com.api.TabHostActivity;


      /**

       * <p>整個流程就像使用ListView自定BaseAdapter一樣</p>

       * 

       * <p>如果要自定義TabHostActivity的Theme,并且不想要頭部陰影

       * 一定要添加這個android:windowContentOverlay = null</p>

       * 

       * <p>如果想在別的項目里面使用TabHostActivity

       * 可以項目的屬性里面找到Android,然后在Library部分添加這個項目(Api)

       * <a >如何添加</a></p>

       * */

      public class ExampleActivity extends TabHostActivity {


          List<TabItem> mItems;

          private LayoutInflater mLayoutInflater;

          

          /**在初始化TabWidget前調(diào)用

           * 和TabWidget有關(guān)的必須在這里初始化*/

          @Override

          protected void prepare() {

              TabItem home = new TabItem(

                      "首頁",                                    // title

                      R.drawable.icon_home,                    // icon

                      R.drawable.example_tab_item_bg,            // background

                      new Intent(this, Tab1Activity.class));    // intent

              

              TabItem info = new TabItem(

                      "資料",

                      R.drawable.icon_selfinfo,

                      R.drawable.example_tab_item_bg,

                      new Intent(this, Tab2Activity.class));

              

              TabItem msg = new TabItem(

                      "信息",

                      R.drawable.icon_meassage,

                      R.drawable.example_tab_item_bg,

                      new Intent(this, Tab3Activity.class));

              

              TabItem square = new TabItem(

                      "廣場",

                      R.drawable.icon_square,

                      R.drawable.example_tab_item_bg,

                      new Intent(this, Tab4Activity.class));

              

              TabItem more = new TabItem(

                      "更多",

                      R.drawable.icon_more,

                      R.drawable.example_tab_item_bg,

                      new Intent(this, Tab5Activity.class));

              

              mItems = new ArrayList<TabItem>();

              mItems.add(home);

              mItems.add(info);

              mItems.add(msg);

              mItems.add(square);

              mItems.add(more);


              // 設(shè)置分割線

              TabWidget tabWidget = getTabWidget();

              tabWidget.setDividerDrawable(R.drawable.tab_divider);

              

              mLayoutInflater = getLayoutInflater();

          }

          

          @Override

          protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              setCurrentTab(0);

          }

          

          /**tab的title,icon,邊距設(shè)定等等*/

          @Override

          protected void setTabItemTextView(TextView textView, int position) {

              textView.setPadding(3, 3, 3, 3);

              textView.setText(mItems.get(position).getTitle());

              textView.setBackgroundResource(mItems.get(position).getBg());

              textView.setCompoundDrawablesWithIntrinsicBounds(0, mItems.get(position).getIcon(), 0, 0);

              

          }

          

          /**tab唯一的id*/

          @Override

          protected String getTabItemId(int position) {

              return mItems.get(position).getTitle();    // 我們使用title來作為id,你也可以自定

          }


          /**點擊tab時觸發(fā)的事件*/

          @Override

          protected Intent getTabItemIntent(int position) {

              return mItems.get(position).getIntent();

          }


          @Override

          protected int getTabItemCount() {

              return mItems.size();

          }

          

          /**自定義頭部文件*/

          @Override

          protected View getTop() {

              return mLayoutInflater.inflate(R.layout.example_top, null);

          }

      }


      框架代碼:

      package com.api;


      import android.app.TabActivity;

      import android.content.Intent;

      import android.os.Bundle;

      import android.view.LayoutInflater;

      import android.view.View;

      import android.widget.LinearLayout;

      import android.widget.TabHost;

      import android.widget.TabHost.TabSpec;

      import android.widget.TabWidget;

      import android.widget.TextView;


      public abstract class TabHostActivity extends TabActivity {


          private TabHost mTabHost;

          private TabWidget mTabWidget;

          private LayoutInflater mLayoutflater;


          @Override

          protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              // set theme because we do not want the shadow

              setTheme(R.style.Theme_Tabhost);

              setContentView(R.layout.api_tab_host);

              

              mLayoutflater = getLayoutInflater();


              mTabHost = getTabHost();

              mTabWidget = getTabWidget();

              //mTabWidget.setStripEnabled(false);    // need android2.2

              

              prepare();


              initTop();

              initTabSpec();

          }

          

          private void initTop() {

              View child = getTop();

              LinearLayout layout = (LinearLayout) findViewById(R.id.tab_top);

              layout.addView(child);

          }


          private void initTabSpec() {


              int count = getTabItemCount();


              for (int i = 0; i < count; i++) {

                  // set text view

                  View tabItem = mLayoutflater.inflate(R.layout.api_tab_item, null);

                  

                  TextView tvTabItem = (TextView) tabItem.findViewById(R.id.tab_item_tv);

                  setTabItemTextView(tvTabItem, i);

                  // set id

                  String tabItemId = getTabItemId(i);

                  // set tab spec

                  TabSpec tabSpec = mTabHost.newTabSpec(tabItemId);

                  tabSpec.setIndicator(tabItem);

                  tabSpec.setContent(getTabItemIntent(i));

                  

                  mTabHost.addTab(tabSpec);

              }


          }


          /** 在初始化界面之前調(diào)用 */

          protected void prepare() {

              // do nothing or you override it

          }


          /** 自定義頭部布局 */

          protected View getTop() {

              // do nothing or you override it

              return null;

          }

          

          protected int getTabCount() {

              return mTabHost.getTabWidget().getTabCount();

          }


          /** 設(shè)置TabItem的圖標(biāo)和標(biāo)題等*/

          abstract protected void setTabItemTextView(TextView textView, int position);


          abstract protected String getTabItemId(int position);

          

          abstract protected Intent getTabItemIntent(int position);


          abstract protected int getTabItemCount();

          

          protected void setCurrentTab(int index) {

              mTabHost.setCurrentTab(index);

          }

          

          protected void focusCurrentTab(int index) {

              mTabWidget.focusCurrentTab(index);

          }

      }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約