Before want to realize the sliding effect of the page, search on the internet, quite a lot of examples of the use of tabhost, and then the use of tabhost, but the effect is very general (maybe I will not use). Then the students introduce the use of Viewpager, on the internet asked hundred teachers, quite a lot of examples quite detailed, personally tried the next, made the effect I want, and now summarize the following:
1. Build a master activity, inherit fragmentactivity, create a adapter class, inherit Fragmentpageradapter (inherit other adapter not tested), Use the same way as the adapter of the ListView. Then implement the corresponding method, according to your needs to achieve.
You need to add code to the layout file:
< Android.support.v4.view.ViewPager Android:id = "@+id/viewpager" android:layout_width= "Match_parent" android:layout_height= "Match_ Parent " android:layout_above=" @id/titlelayout "></ Android.support.v4.view.ViewPager >
2. Then create the class of the page, all to inherit fragment, and implement the Oncreateview method, where the layout is obtained using Inflater to get and set the code as follows:
@Override Public voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub Super. OnCreate (savedinstancestate); Layoutinflater Layoutinflater=getactivity (). Getlayoutinflater (); Mmainview=layoutinflater.inflate (R.layout.activity_discovery, (ViewGroup) getactivity (). Findviewbyid (R.layout.ac Tivity_main),false); } @Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {//TODO auto-generated Method StubViewGroup p =(ViewGroup) mmainview.getparent (); if(P! =NULL) {p.removeallviewsinlayout (); LOG.V ("Huahua", "fragment1--> removal of existing view"); } returnMmainview; }
This is basically the two steps, even if the Viewpager is done.
Note: Purely individual study notes, have no understanding or have other different views, can be said in the comments, very happy to discuss together