Search in sources :

Example 86 with ViewPager

use of android.support.v4.view.ViewPager in project ViewPagerIndicator by LuckyJayce.

the class FirstLayerFragment method onCreateViewLazy.

@Override
protected void onCreateViewLazy(Bundle savedInstanceState) {
    super.onCreateViewLazy(savedInstanceState);
    setContentView(R.layout.fragment_tabmain);
    Resources res = getResources();
    Bundle bundle = getArguments();
    tabName = bundle.getString(INTENT_STRING_TABNAME);
    index = bundle.getInt(INTENT_INT_INDEX);
    ViewPager viewPager = (ViewPager) findViewById(R.id.fragment_tabmain_viewPager);
    Indicator indicator = (Indicator) findViewById(R.id.fragment_tabmain_indicator);
    switch(index) {
        case 0:
            indicator.setScrollBar(new ColorBar(getApplicationContext(), Color.RED, 5));
            break;
        case 1:
            indicator.setScrollBar(new ColorBar(getApplicationContext(), Color.RED, 0, Gravity.CENTENT_BACKGROUND));
            break;
        case 2:
            indicator.setScrollBar(new ColorBar(getApplicationContext(), Color.RED, 5, Gravity.TOP));
            break;
        case 3:
            indicator.setScrollBar(new LayoutBar(getApplicationContext(), R.layout.layout_slidebar, Gravity.CENTENT_BACKGROUND));
            break;
    }
    float unSelectSize = 16;
    float selectSize = unSelectSize * 1.2f;
    int selectColor = res.getColor(R.color.tab_top_text_2);
    int unSelectColor = res.getColor(R.color.tab_top_text_1);
    indicator.setOnTransitionListener(new OnTransitionTextListener().setColor(selectColor, unSelectColor).setSize(selectSize, unSelectSize));
    viewPager.setOffscreenPageLimit(4);
    indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
    inflate = LayoutInflater.from(getApplicationContext());
    // 注意这里 的FragmentManager 是 getChildFragmentManager(); 因为是在Fragment里面
    // 而在activity里面用FragmentManager 是 getSupportFragmentManager()
    indicatorViewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
    Log.d("cccc", "Fragment 将要创建View " + this);
}
Also used : IndicatorViewPager(com.shizhefei.view.indicator.IndicatorViewPager) Bundle(android.os.Bundle) OnTransitionTextListener(com.shizhefei.view.indicator.transition.OnTransitionTextListener) Resources(android.content.res.Resources) LayoutBar(com.shizhefei.view.indicator.slidebar.LayoutBar) IndicatorViewPager(com.shizhefei.view.indicator.IndicatorViewPager) ViewPager(android.support.v4.view.ViewPager) Indicator(com.shizhefei.view.indicator.Indicator) ColorBar(com.shizhefei.view.indicator.slidebar.ColorBar)

Example 87 with ViewPager

use of android.support.v4.view.ViewPager in project CircleDemo by Naoki2015.

the class ImagePagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imagepager);
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    guideGroup = (LinearLayout) findViewById(R.id.guideGroup);
    getIntentData();
    ImageAdapter mAdapter = new ImageAdapter(this);
    mAdapter.setDatas(imgUrls);
    mAdapter.setImageSize(imageSize);
    viewPager.setAdapter(mAdapter);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            for (int i = 0; i < guideViewList.size(); i++) {
                guideViewList.get(i).setSelected(i == position ? true : false);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    viewPager.setCurrentItem(startPos);
    addGuideView(guideGroup, startPos, imgUrls);
}
Also used : ViewPager(android.support.v4.view.ViewPager)

Example 88 with ViewPager

use of android.support.v4.view.ViewPager in project Carbon by ZieIony.

the class PagerTabStrip method initTabs.

private void initTabs() {
    content.removeAllViews();
    if (viewPager == null)
        return;
    final PagerAdapter adapter = viewPager.getAdapter();
    if (viewPager.getAdapter() == null)
        return;
    if (tabBuilder == null) {
        tabBuilder = position -> {
            View tab = inflate(getContext(), R.layout.carbon_tab, null);
            ((TextView) tab.findViewById(R.id.carbon_tabText)).setText(getViewPager().getAdapter().getPageTitle(position).toString().toUpperCase());
            return tab;
        };
    }
    for (int i = 0; i < adapter.getCount(); i++) {
        View tab = tabBuilder.getView(i);
        content.addView(tab, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
        tab.setSelected(i == 0);
        final int finalI = i;
        tab.setOnClickListener(__ -> viewPager.setCurrentItem(finalI));
    }
}
Also used : View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) Paint(android.graphics.Paint) LinearLayout(android.widget.LinearLayout)

Example 89 with ViewPager

use of android.support.v4.view.ViewPager in project remusic by aa112901.

the class PlayingActivity method setViewPager.

private void setViewPager() {
    mViewPager.setOffscreenPageLimit(2);
    PlaybarPagerTransformer transformer = new PlaybarPagerTransformer();
    mAdapter = new FragmentAdapter(getSupportFragmentManager());
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageTransformer(true, transformer);
    // 改变viewpager动画时间
    try {
        Field mField = ViewPager.class.getDeclaredField("mScroller");
        mField.setAccessible(true);
        MyScroller mScroller = new MyScroller(mViewPager.getContext().getApplicationContext(), new LinearInterpolator());
        mField.set(mViewPager, mScroller);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(final int pPosition) {
            if (pPosition < 1) {
                //首位之前,跳转到末尾(N)
                MusicPlayer.setQueuePosition(MusicPlayer.getQueue().length);
                mViewPager.setCurrentItem(MusicPlayer.getQueue().length, false);
                isNextOrPreSetPage = false;
                return;
            } else if (pPosition > MusicPlayer.getQueue().length) {
                //末位之后,跳转到首位(1)
                MusicPlayer.setQueuePosition(0);
                //false:不显示跳转过程的动画
                mViewPager.setCurrentItem(1, false);
                isNextOrPreSetPage = false;
                return;
            } else {
                if (!isNextOrPreSetPage) {
                    if (pPosition < MusicPlayer.getQueuePosition() + 1) {
                        //                            HandlerUtil.getInstance(PlayingActivity.this).postDelayed(new Runnable() {
                        //                                @Override
                        //                                public void run() {
                        //                                  //  MusicPlayer.previous(PlayingActivity.this, true);
                        //                                    Message msg = new Message();
                        //                                    msg.what = 0;
                        //                                    mPlayHandler.sendMessage(msg);
                        //                                }
                        //                            }, 500);
                        Message msg = new Message();
                        msg.what = PRE_MUSIC;
                        mPlayHandler.sendMessageDelayed(msg, TIME_DELAY);
                    } else if (pPosition > MusicPlayer.getQueuePosition() + 1) {
                        //                            HandlerUtil.getInstance(PlayingActivity.this).postDelayed(new Runnable() {
                        //                                @Override
                        //                                public void run() {
                        //                                  //  MusicPlayer.mNext();
                        //
                        //
                        //                                }
                        //                            }, 500);
                        Message msg = new Message();
                        msg.what = NEXT_MUSIC;
                        mPlayHandler.sendMessageDelayed(msg, TIME_DELAY);
                    }
                }
            }
            //MusicPlayer.setQueuePosition(pPosition - 1);
            isNextOrPreSetPage = false;
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageScrollStateChanged(int pState) {
        }
    });
}
Also used : Message(android.os.Message) AlbumViewPager(com.wm.remusic.widget.AlbumViewPager) ViewPager(android.support.v4.view.ViewPager) Field(java.lang.reflect.Field) LinearInterpolator(android.view.animation.LinearInterpolator)

Example 90 with ViewPager

use of android.support.v4.view.ViewPager in project remusic by aa112901.

the class TabPagerFragment method setupViewPager.

private void setupViewPager(ViewPager viewPager) {
    Adapter adapter = new Adapter(getChildFragmentManager());
    adapter.addFragment(new MusicFragment(), title[0]);
    adapter.addFragment(new ArtistFragment(), title[1]);
    adapter.addFragment(new AlbumFragment(), title[2]);
    adapter.addFragment(new FolderFragment(), title[3]);
    viewPager.setAdapter(adapter);
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter)

Aggregations

ViewPager (android.support.v4.view.ViewPager)246 View (android.view.View)95 PagerAdapter (android.support.v4.view.PagerAdapter)55 Fragment (android.support.v4.app.Fragment)44 TabLayout (android.support.design.widget.TabLayout)37 TextView (android.widget.TextView)35 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)34 Toolbar (android.support.v7.widget.Toolbar)30 Bundle (android.os.Bundle)28 ViewGroup (android.view.ViewGroup)27 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)21 ImageView (android.widget.ImageView)20 ArrayList (java.util.ArrayList)20 Intent (android.content.Intent)17 ActionBar (android.support.v7.app.ActionBar)15 RecyclerView (android.support.v7.widget.RecyclerView)11 ViewTreeObserver (android.view.ViewTreeObserver)9 AdapterView (android.widget.AdapterView)9 LinearLayout (android.widget.LinearLayout)9 UiController (android.support.test.espresso.UiController)8