Combination of tabhost and viewpager in Android to achieve home page navigation effect
Today, I sent tabhost and viewpager to achieve the effect of navigation at the bottom of the home page. Although there are many such demos on the Internet, I still want to send out my own practice writing. That's right! Is so capricious;
First, the renderings are as follows:
There are comments in the code, but I don't need to explain more. I said some problems that need to be paid attention to
1: The ID attribute must be added to tabhost, tabwidget and FrameLayout, otherwise an error will be reported
android:id=”@android:id/tabhost”
android:id=”@android:id/tabcontent”
android:id=”@android:id/tabs”
This property is fixed.
2: The adapter of viewpager should inherit pageradapter. Don't make a mistake;
Layout file XML:
Activity:
Viewpager adapter myadapter:
The above is what Xiaobian introduced to you. The combination of tabhost and viewpager in Android realizes the home page navigation effect. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!