About Viewpagerindicator's study and summary

Source: Internet
Author: User

This paper mainly discusses how to use and summarize the two kinds of interfaces of Tabpageindicator and Underlinepageindicator:

I started with the viewpager+fragment implementation of the main interface, and then the teacher told me that using WPS main interface Layout way effect may be better ~ ~ ~ Toss for several hours finally to understand the usage of tabpageindicator, also wrote the demo ... In the process of the realization of the human egg is the. 9path diagram of the problem, we all know that eclipse's requirements for 9path diagram is not particularly strict, which led to a lot of 9path diagram moved to the studio on the cause of the failure to parse the picture. Sweat!!! Then finally found a can achieve the figure, and then found in addition to the style of the customization of a little cumbersome, but also a bit unacceptable is in the viewpager around the time, the top of the indicator seems to have no transition effect ... As a Scorpio but I have a Virgo problem, after-school time has been looking for the transition effect to achieve the way ... Finally found in the Viewpagerindicator Open Source Library to the demo there is a underlinepage called the demo can have a transition effect!!! Surprise!!! , although there is no tab, only a bare indicator bar, but this basically let me have a little idea!!! So ...

Look at the source code, found that the use of underlinepagerindicator and tabpageindicator of the use of almost the same, and then Tiger wrote a demo (unfortunately no tab), Then found that we were doing viewpager+fragment implementation, the linkage effect is based on the monitoring Viewpager onpageselected () method to achieve, haha ~ ~ ~ you know, and then I wrote a layout with tabs, Then listen to each other, in the method of listening to the text color of the option card linkage changes can achieve the purpose!!!


The main source of Tabpageindicator is posted here:

<span style= "FONT-SIZE:14PX;" >public class Tabs extends Fragment {    @Override public    View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {        View view= inflater.inflate (r.layout.tabs,container,false);// The last item is the parent layout, set to False        TextView content= (TextView) View.findviewbyid (r.id.tv);        Savedinstancestate is the data        Bundle bundle= getarguments () that is saved by itself;        String title= bundle.getstring ("arg");//extract data from the activity from the bundle        Content.settext (title);        return view;}    } </span>


<span style= "FONT-SIZE:14PX;" >package Com.bob.indicatortab;import Android.support.v4.app.fragment;import Android.support.v4.app.fragmentactivity;import Android.os.bundle;import Android.support.v4.app.FragmentManager; Import Android.support.v4.app.fragmentpageradapter;import Android.support.v4.view.viewpager;import Com.viewpagerindicator.pageindicator;public class Mainactivity extends Fragmentactivity {public static final String Ti    tles[]= {"New", "Ferry", "my"};    Private Viewpager Pager;    Private Pageindicator indicator;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Pager= (Viewpager) Findviewbyid (R.id.pager); Fragmentpageradapter adapter= New Tabpageindicatoradapter (Getsupportfragmentmanager ());//Create Data adapter Pager.setAdapter (        adapter); Indicator= (Pageindicator) Findviewbyid (r.id.indicator);//core code is actually the two sentences Indicator.setviewpager (pager);//Will INdicator and Viewpager to bind/* Two settings page switching monitoring method Indicator.setonpagechangelistener (); Pager.setonpagechangelistener (); */} Class Tabpageindicatoradapter extends fragmentpageradapter{public TABPA        Geindicatoradapter (fragmentmanager FM) {//construct the parent class super (FM);            } @Override public Fragment getItem (int position) {Fragment fragment= new Tabs ();            Bundle args= New Bundle ();            Args.putstring ("Arg", titles[position]);        Fragment.setarguments (args);//Add bundle data Bundle for fragment args return fragment;        } @Override public int getcount () {return titles.length;            }//Create a Fragmentpageradapter adapter that supports indicator @Override public charsequence getpagetitle (int position) {        return titles[position]; }}}</span>
****************** Note *******************

Here in order to facilitate the diagram, I should be a number of fragment implementation of the page with a fragment instead of, if more than one page layout is the same, adopt one also can NOT!!!

We can carefully observe and observe, found that simple use of tabpageindicator is actually very simple, of course, let a little bit of egg pain is it in the style of configuration indicator parameters and 9path diagram of the problem, Then we can use the analogy of the method to achieve underlinepageindicator, plus a layout and linkage effect will naturally be able to achieve the effect we want!!! The realization of linkage effect can refer to my blog;

The reason why do not put out Underlinepageindicator source code, is to let everyone on what I said serious thinking, source in the bottom of GitHub ~ ~ ~

Project Address (Studio)

About Viewpagerindicator's study and summary

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.