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

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

    • 分享

      使用TabHost實現(xiàn)類網易新聞

       ada_lib 2015-04-05
      先貼圖看效果



      Activity代碼:
      1. package com.jay.test;


      2. import android.app.Activity;
      3. import android.os.Bundle;
      4. import android.widget.ImageButton;
      5. import android.widget.TabHost;
      6. import android.widget.TabHost.OnTabChangeListener;
      7. import android.widget.TabHost.TabSpec;

      8. public class BottmoMenuBarActivity extends Activity {
      9.     private TabHost tabs;
      10.         private ImageButton footer_tab_btn1;
      11.         private ImageButton footer_tab_btn2;
      12.         private ImageButton footer_tab_btn3;
      13.         private ImageButton footer_tab_btn4;
      14.         private ImageButton footer_tab_btn5;
      15.         private ImageButton footer_tab_btn6;
      16.         private ImageButton footer_tab_btn7;

      17.         /** Called when the activity is first created. */
      18.     @Override
      19.     public void onCreate(Bundle savedInstanceState) {
      20.         super.onCreate(savedInstanceState);
      21.         setContentView(R.layout.main);
      22.         
      23.         tabs = null;
      24.                 tabs = (TabHost)findViewById(R.id.tabhost);
      25.                 tabs.setup();
      26.         tabs.setOnTabChangedListener(TabChangeListener);
      27.         //設置Tab1
      28.         footer_tab_btn1 = new ImageButton(this);
      29.         footer_tab_btn1.setBackgroundResource(R.drawable.bottom_home_button);
      30.         TabSpec tab1 = tabs.newTabSpec("home");  
      31.         tab1.setIndicator(footer_tab_btn1);      // 設置tab1的名稱
      32.         tab1.setContent(R.id.text1);    // 關聯(lián)控件  
      33.         tabs.addTab(tab1);                // 添加tab1  
      34.         
      35.          
      36.         //設置Tab2
      37.         footer_tab_btn2 = new ImageButton(this);
      38.         footer_tab_btn2.setBackgroundResource(R.drawable.bottom_book_button);
      39.         TabSpec tab2 = tabs.newTabSpec("book");  
      40.         tab2.setIndicator(footer_tab_btn2);  
      41.         tab2.setContent(R.id.text2);   
      42.         tabs.addTab(tab2);               
      43.         
      44.         //設置Tab3  
      45.         footer_tab_btn3 = new ImageButton(this);
      46.         footer_tab_btn3.setBackgroundResource(R.drawable.bottom_video_button);
      47.         TabSpec tab3 = tabs.newTabSpec("video");  
      48.         tab3.setIndicator(footer_tab_btn3);        
      49.         tab3.setContent(R.id.text3);   
      50.         tabs.addTab(tab3);               

      51.         //設置Tab4  
      52.         footer_tab_btn4 = new ImageButton(this);
      53.         footer_tab_btn4.setBackgroundResource(R.drawable.bottom_magazine_button);
      54.         TabSpec tab4 = tabs.newTabSpec("magazine");  
      55.         tab4.setIndicator(footer_tab_btn4);        
      56.         tab4.setContent(R.id.text4);     
      57.         tabs.addTab(tab4);   
      58.         
      59.         // 設置Tab5
      60.         footer_tab_btn5 = new ImageButton(this);
      61.         footer_tab_btn5.setBackgroundResource(R.drawable.bottom_paper_button);
      62.         TabSpec tab5 = tabs.newTabSpec("paper");  
      63.         tab5.setIndicator(footer_tab_btn5);        
      64.         tab5.setContent(R.id.text5);     
      65.         tabs.addTab(tab5);   
      66.         
      67.         // 設置Tab6
      68.         footer_tab_btn6 = new ImageButton(this);
      69.         footer_tab_btn6.setBackgroundResource(R.drawable.bottom_thesis_button);
      70.         TabSpec tab6 = tabs.newTabSpec("thesis");  
      71.         tab6.setIndicator(footer_tab_btn6);        
      72.         tab6.setContent(R.id.text6);     
      73.         tabs.addTab(tab6);   
      74.         
      75.         // 設置Tab7
      76.         footer_tab_btn7 = new ImageButton(this);
      77.         footer_tab_btn7.setBackgroundResource(R.drawable.bottom_library_button);
      78.         TabSpec tab7 = tabs.newTabSpec("library");  
      79.         tab7.setIndicator(footer_tab_btn7);        
      80.         tab7.setContent(R.id.text7);      
      81.         tabs.addTab(tab7);   
      82.     }
      83.     private OnTabChangeListener TabChangeListener  = new OnTabChangeListener() {
      84.                
      85.                 @Override
      86.                 public void onTabChanged(String tabId) {
      87.                         int j = tabs.getTabWidget().getTabCount();
      88.                         ImageButton currentView =(ImageButton) tabs.getCurrentTabView();
      89.                         for (int i = 0; i < j ; i++){
      90.                                 if(tabs.getCurrentTab() == i){
      91.                                         currentView.setEnabled(false);
      92.                                 }else{
      93.                                         if(tabs.getTabWidget().getChildTabViewAt(i) != null){
      94.                                                 ((ImageButton)tabs.getTabWidget().getChildTabViewAt(i)).setEnabled(true);
      95.                                         }
      96.                                 }
      97.                         }
      98.                 }
      99.         };;
      100. }
      復制代碼
      一些注意點:
      1.沒有使用TabActivity,這是在3.0中不建議使用的。
      2.setContent()函數(shù)除了直接添加視圖ID,還可以添加intent直接在Tab的內容部分打開一個activity。如需要了解詳細實現(xiàn)過程可自行搜索,也可以發(fā)郵件至我的郵箱jayzhou215@163.com
      3.重載onTabChanged(String tabId) 函數(shù)的目的是實現(xiàn)按下面按鈕時變藍的效果,具體請查看源碼
      4.之所以菜單欄會在底部顯示是在TabHost和TabWidget之間加了一層RelativeLayout,將TabWidget設置為alignParentBottom即可。
      main.xml源碼:
      1. <?xml version="1.0" encoding="utf-8"?>
      2. <RelativeLayout
      3.     xmlns:android="http://schemas./apk/res/android"
      4.     xmlns:tools="http://schemas./tools"
      5.         android:layout_width="fill_parent"
      6.         android:layout_height="fill_parent"
      7.         >
      8.         <TabHost
      9.                 android:layout_width="fill_parent"
      10.                 android:layout_height="fill_parent"
      11.                 android:id="@+id/tabhost"
      12.             tools:ignore="UselessParent" >
      13.             <RelativeLayout
      14.                         android:layout_width="fill_parent"
      15.                         android:layout_height="match_parent"
      16.                         >
      17.                     <TabWidget
      18.                         android:id="@android:id/tabs"
      19.                         android:layout_width="fill_parent"
      20.                         android:layout_height="50dp"
      21.                         android:layout_alignParentBottom="true"
      22.                         >
      23.                     </TabWidget>
      24.                
      25.                     <FrameLayout
      26.                         android:id="@android:id/tabcontent"
      27.                         android:layout_width="fill_parent"
      28.                         android:layout_height="fill_parent"
      29.                                 android:layout_above="@android:id/tabs"
      30.                         >
      31.                         <TextView
      32.                                 android:layout_width="fill_parent"
      33.                                 android:layout_height="fill_parent"
      34.                                 android:text="@string/text1"
      35.                                 android:id="@+id/text1"
      36.                             />
      37.                         <TextView
      38.                                 android:layout_width="fill_parent"
      39.                                 android:layout_height="fill_parent"
      40.                                 android:text="@string/text2"
      41.                                 android:id="@+id/text2"
      42.                             />
      43.                         <TextView
      44.                                 android:layout_width="fill_parent"
      45.                                 android:layout_height="fill_parent"
      46.                                 android:text="@string/text3"
      47.                                 android:id="@+id/text3"
      48.                             />
      49.                         <TextView
      50.                                 android:layout_width="fill_parent"
      51.                                 android:layout_height="fill_parent"
      52.                                 android:text="@string/text4"
      53.                                 android:id="@+id/text4"
      54.                             />
      55.                         <TextView
      56.                                 android:layout_width="fill_parent"
      57.                                 android:layout_height="fill_parent"
      58.                                 android:text="@string/text5"
      59.                                 android:id="@+id/text5"
      60.                             />
      61.                         <TextView
      62.                                 android:layout_width="fill_parent"
      63.                                 android:layout_height="fill_parent"
      64.                                 android:text="@string/text6"
      65.                                 android:id="@+id/text6"
      66.                             />
      67.                         <TextView
      68.                                 android:layout_width="fill_parent"
      69.                                 android:layout_height="fill_parent"
      70.                                 android:text="@string/text7"
      71.                                 android:id="@+id/text7"
      72.                             />
      73.                     </FrameLayout>
      74.                 </RelativeLayout>
      75.         </TabHost>
      76. </RelativeLayout>
      復制代碼
      游客,如果您要查看本帖隱藏內容請回復

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

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多