Search in sources :

Example 1 with FragmentContainerHelper

use of net.lucode.hackware.magicindicator.FragmentContainerHelper in project MagicIndicator by hackware1993.

the class FixedTabExampleActivity method initMagicIndicator4.

private void initMagicIndicator4() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator4);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

        @Override
        public int getCount() {
            return mDataList.size();
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
            simplePagerTitleView.setNormalColor(Color.GRAY);
            simplePagerTitleView.setSelectedColor(Color.WHITE);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mViewPager.setCurrentItem(index);
                }
            });
            return simplePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
            linePagerIndicator.setMode(LinePagerIndicator.MODE_EXACTLY);
            linePagerIndicator.setLineWidth(UIUtil.dip2px(context, 10));
            linePagerIndicator.setColors(Color.WHITE);
            return linePagerIndicator;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    // must after setNavigator
    LinearLayout titleContainer = commonNavigator.getTitleContainer();
    titleContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    titleContainer.setDividerDrawable(new ColorDrawable() {

        @Override
        public int getIntrinsicWidth() {
            return UIUtil.dip2px(FixedTabExampleActivity.this, 15);
        }
    });
    final FragmentContainerHelper fragmentContainerHelper = new FragmentContainerHelper(magicIndicator);
    fragmentContainerHelper.setInterpolator(new OvershootInterpolator(2.0f));
    fragmentContainerHelper.setDuration(300);
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            fragmentContainerHelper.handlePageSelected(position);
        }
    });
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) OvershootInterpolator(android.view.animation.OvershootInterpolator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) ViewPager(android.support.v4.view.ViewPager) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) FragmentContainerHelper(net.lucode.hackware.magicindicator.FragmentContainerHelper) ColorDrawable(android.graphics.drawable.ColorDrawable) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) LinearLayout(android.widget.LinearLayout)

Aggregations

Context (android.content.Context)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 OvershootInterpolator (android.view.animation.OvershootInterpolator)1 LinearLayout (android.widget.LinearLayout)1 FragmentContainerHelper (net.lucode.hackware.magicindicator.FragmentContainerHelper)1 MagicIndicator (net.lucode.hackware.magicindicator.MagicIndicator)1 CommonNavigator (net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator)1 CommonNavigatorAdapter (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter)1 IPagerIndicator (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator)1 IPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView)1 LinePagerIndicator (net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator)1 ClipPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView)1 ColorTransitionPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView)1 SimplePagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView)1 ScaleTransitionPagerTitleView (net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView)1