Android之TabHost重定義

來源:互聯網
上載者:User

更多參考:http://www.360doc.com/content/12/0515/13/7857928_211171985.shtml


TabHost的布局:

<?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:id="@+id/linearLayout1"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical" >        <TabWidget            android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content" >        </TabWidget>        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="fill_parent" >        </FrameLayout>    </LinearLayout></TabHost>

 

TabHost的主檔案:

public class MainActivity extends TabActivity {    String[] title = new String[]{"ni","wo","ta","we"};      View userTab,articeTab,feedTab,weTab;      View[] tabs = new View[]{userTab,articeTab,feedTab,weTab};      @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                TabHost tabHost = getTabHost();          tabHost.setup();   //Call setup() before adding tabs if loading TabHost using findViewById().                     for(int i=0;i<tabs.length;i++){             Intent intent = new Intent(this,AActivity.class);            tabs[i] = (View) LayoutInflater.from(this).inflate(R.layout.tabmini, null);              ImageView text = (ImageView) tabs[i].findViewById(R.id.tab_label);                         tabHost.addTab(tabHost.newTabSpec(title[i]).setIndicator(tabs[i]).setContent(intent));             tabHost.setCurrentTab(1);        }      }}

 

 

TabHost裡面的布局(tabmini.xml):

<?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"        android:layout_width="fill_parent"      android:layout_height="40dp"      android:paddingLeft="5dip"      android:paddingRight="5dip"      android:background="#ff0000">              <ImageView android:id="@+id/tab_label"            android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:layout_centerInParent="true"          android:gravity="center"          android:background="@drawable/btndown"        />   </RelativeLayout>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.