Using tabhost and fragment to make page switching effect in Android

Three tabs at the top

design sketch:

Define the effect of page switching in the file boardtabhost.java; When switching pages, the current page slides out and the target page slides in. These are two different animations, which should be treated differently when animating

Corresponding layout file activity_ board.xml

Use boardtabhost to load a vertical LinearLayout; Above is tabwidget, which loads tags; The following is the FrameLayout of the fragment. You can see that there are three fragments here, and three tags will be set in the activity later

It is worth mentioning that the ID here should use the ID specified by Android; For example, @ Android: ID / tabhost, @ Android: ID / tabcontent, @ Android: ID / tabs; Otherwise, the system will report an error because it cannot find the corresponding control

Three tabs are set in boardactivity.java, and the fragment corresponding to the tab is specified

Main file directory:

── layout

├── activity_ board.xml ├── fragment_ tab1.xml ├── fragment_ tab2.xml └── fragment_ tab3.xml

── tabhostdemo

├── BoardActivity.java ├── BoardTabHost.java ├── TabFragment1.java ├── TabFragment2.java └── TabFragment3.java

The above is what Xiaobian introduced to you about using tabhost and fragment to make page switching effect in Android. I hope it will be helpful to you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>