Android tab Effect

Source: Internet
Author: User

Http://www.javaeye.com/topic/465371

To create a tabhost in Main. xml or a custom *. xml file, two elements tabwidget and framelayout are required to put the two elements in linearlayout. Framelayout is used to change the content.


Note: tabwidget and framelayout have different ID namespaces: Android: Id = "@ Android: ID/idnames". This is required, so tabhost can be automatically found. The activity must inherit tabactivity.

Tabhost control-> tabwidget (must be named tabs)-> framelayout (must be named tabcontent ).

 

  1. <? XMLVersion = "1.0" encoding = "UTF-8"?>
  2. <TabhostXmlns: Android = "http://schemas.android.com/apk/res/android"
  3. Android: Id = "@ Android: ID/tabhost"
  4. Android: layout_width = "fill_parent"
  5. Android: layout_height = "fill_parent">
  6. <Linearlayout
  7. Android: Orientation = "vertical"
  8. Android: layout_width = "fill_parent"
  9. Android: layout_height = "fill_parent">
  10. <Tabwidget
  11. Android: Id = "@ Android: ID/tabs"
  12. Android: layout_width = "fill_parent"
  13. Android: layout_height = "wrap_content"/>
  14. <Framelayout
  15. Android: Id = "@ Android: ID/tabcontent"
  16. Android: layout_width = "fill_parent"
  17. Android: layout_height = "fill_parent">
  18. <Textview
  19. Android: Id = "@ + ID/textview1"
  20. Android: layout_width = "fill_parent"
  21. Android: layout_height = "fill_parent"
  22. Android: text = "this is a tab"/>
  23. <Textview
  24. Android: Id = "@ + ID/textview2"
  25. Android: layout_width = "fill_parent"
  26. Android: layout_height = "fill_parent"
  27. Android: text = "this is another tab"/>
  28. <Textview
  29. Android: Id = "@ + ID/textview3"
  30. Android: layout_width = "fill_parent"
  31. Android: layout_height = "fill_parent"
  32. Android: text = "this is a third tab"/>
  33. </Framelayout>
  34. </Linearlayout>
  35. </Tabhost>

Public ClassHellotabwidgetExtendsTabactivity

  1. Public VoidOncreate (bundle savedinstancestate ){
  2. Super. Oncreate (savedinstancestate );
  3. Setcontentview (R. layout. Main );
  4. Mtabhost = gettabhost ();
  5. Mtabhost. addtab (mtabhost. newtabspec ("tab_test1"). setindicator ("Tab 1"). setcontent (R. Id. textview1 ));
  6. Mtabhost. addtab (mtabhost. newtabspec ("tab_test2"). setindicator ("Tab 2"). setcontent (R. Id. textview2 ));
  7. Mtabhost. addtab (mtabhost. newtabspec ("tab_test3"). setindicator ("tab 3"). setcontent (R. Id. textview3 ));
  8. Mtabhost. setcurrenttab (0 );
  9. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.