我想实现在同一个ViewPager和TitlePageIndicator一个CirclePageIndicator [英] I am trying to implement a TitlePageIndicator and a CirclePageIndicator on the same ViewPager

查看:180
本文介绍了我想实现在同一个ViewPager和TitlePageIndicator一个CirclePageIndicator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个TitlePageIndicator和CirclePageIndicator创造的东西是这样的:

I am trying to implement a TitlePageIndicator and a CirclePageIndicator to create something like this:

这是我的code:

    pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
    ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
    pager.setAdapter(pageAdapter);

    TitlePageIndicator mWordIndicator = (TitlePageIndicator)findViewById(R.id.word_indicator);
    mWordIndicator.setViewPager(pager);
    mWordIndicator.setOnPageChangeListener(pageListener);

    CirclePageIndicator indicator = (CirclePageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
    indicator.setOnPageChangeListener(pageListener);

OnPageChangeListener pageListener = new OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
        // TODO Auto-generated method stub
        on_page_selected = position;
        titleText.setText(pageTitle.get(position));
        setPageImages();

    }

    @Override
    public void onPageScrolled(int position, float arg1, int arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onPageScrollStateChanged(int arg0) {
        // TODO Auto-generated method stub

    }
};

的问题是,只有一个指示器工作在一个时间。如果我评论一出,其他作品。如果我离开都注释掉,只有CirclePageIndicator工作。你有我如何才能做到这一点有什么建议?或者是有,我可以用它来实现我的目标的另一个库?谢谢你在前进!

The problem is that only one indicator works at a time. If I comment one out, the other works. If I leave both uncommented, only the CirclePageIndicator works. Do you have any suggestions of how I can achieve this? Or is there another library that I can use to accomplish my goal? Thank you in advance!

PS - 我发现了一个问题,重复的<一个href=\"http://stackoverflow.com/questions/11132741/titlepageindicator-circlepageindicator-both-on-same-viewpager\">here,但没有给出答案

PS - I found a duplicate question here, but there was no answer given.

推荐答案

为了解决这个问题,您应该手动调用第一PageIndicator的OnPageChangeListener回调函数。喜欢:

In order to solve this problem, you should manually call the first PageIndicator's OnPageChangeListener callback functions. Likes:

pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);

CirclePageIndicator indicator = (CirclePageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(pager);


TitlePageIndicator mWordIndicator = (TitlePageIndicator)findViewById(R.id.word_indicator);
mWordIndicator.setViewPager(pager);
mWordIndicator.setOnPageChangeListener(pageListener);



OnPageChangeListener pageListener = new OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
        // TODO Auto-generated method stub
        on_page_selected = position;
        titleText.setText(pageTitle.get(position));
        setPageImages();

        indicator.onPageSelected(position);

    }

    @Override
    public void onPageScrolled(int position, float arg1, int arg2) {
        // TODO Auto-generated method stub
        indicator.onPageScrolled(position, arg1, arg2);
    }

    @Override
    public void onPageScrollStateChanged(int arg0) {
        // TODO Auto-generated method stub

        indicator.onPageScrollStateChanged(arg0);
    }
};

这篇关于我想实现在同一个ViewPager和TitlePageIndicator一个CirclePageIndicator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆