Search in sources :

Example 1 with CommonPagerTitleView

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView in project MagicIndicator by hackware1993.

the class LoadCustomLayoutExampleActivity method initMagicIndicator1.

private void initMagicIndicator1() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1);
    magicIndicator.setBackgroundColor(Color.BLACK);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdjustMode(true);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

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

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(context);
            // load custom layout
            View customLayout = LayoutInflater.from(context).inflate(R.layout.simple_pager_title_layout, null);
            final ImageView titleImg = (ImageView) customLayout.findViewById(R.id.title_img);
            final TextView titleText = (TextView) customLayout.findViewById(R.id.title_text);
            titleImg.setImageResource(R.mipmap.ic_launcher);
            titleText.setText(mDataList.get(index));
            commonPagerTitleView.setContentView(customLayout);
            commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() {

                @Override
                public void onSelected(int index, int totalCount) {
                    titleText.setTextColor(Color.WHITE);
                }

                @Override
                public void onDeselected(int index, int totalCount) {
                    titleText.setTextColor(Color.LTGRAY);
                }

                @Override
                public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {
                    titleImg.setScaleX(1.3f + (0.8f - 1.3f) * leavePercent);
                    titleImg.setScaleY(1.3f + (0.8f - 1.3f) * leavePercent);
                }

                @Override
                public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {
                    titleImg.setScaleX(0.8f + (1.3f - 0.8f) * enterPercent);
                    titleImg.setScaleY(0.8f + (1.3f - 0.8f) * enterPercent);
                }
            });
            commonPagerTitleView.setOnClickListener(new View.OnClickListener() {

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

        @Override
        public IPagerIndicator getIndicator(Context context) {
            return null;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ImageView(android.widget.ImageView) CommonPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView) TextView(android.widget.TextView) View(android.view.View) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) CommonPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

Context (android.content.Context)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)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 CommonPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView)1