Search in sources :

Example 41 with ViewPager

use of android.support.v4.view.ViewPager in project Android-SpinKit by ybq.

the class DetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    viewPager.setOffscreenPageLimit(0);
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return Style.values().length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            @SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null);
            SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit);
            TextView name = (TextView) view.findViewById(R.id.name);
            Style style = Style.values()[position];
            name.setText(style.name());
            Sprite drawable = SpriteFactory.create(style);
            spinKitView.setIndeterminateDrawable(drawable);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, colors[position % colors.length], colors[(position + 1) % colors.length]);
            getWindow().getDecorView().setBackgroundColor(color);
        }

        @Override
        public void onPageSelected(int position) {
            getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    viewPager.setCurrentItem(getIntent().getIntExtra("position", 0));
}
Also used : Sprite(com.github.ybq.android.spinkit.sprite.Sprite) ViewGroup(android.view.ViewGroup) ViewPager(android.support.v4.view.ViewPager) SpinKitView(com.github.ybq.android.spinkit.SpinKitView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) SuppressLint(android.annotation.SuppressLint) Style(com.github.ybq.android.spinkit.Style) TextView(android.widget.TextView) SpinKitView(com.github.ybq.android.spinkit.SpinKitView)

Example 42 with ViewPager

use of android.support.v4.view.ViewPager in project CloudReader by youlookwhat.

the class MainActivity method initContentFragment.

private void initContentFragment() {
    ArrayList<Fragment> mFragmentList = new ArrayList<>();
    mFragmentList.add(new GankFragment());
    mFragmentList.add(new OneFragment());
    mFragmentList.add(new BookFragment());
    // 注意使用的是:getSupportFragmentManager
    MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList);
    vpContent.setAdapter(adapter);
    // 设置ViewPager最大缓存的页面个数(cpu消耗少)
    vpContent.setOffscreenPageLimit(2);
    vpContent.addOnPageChangeListener(this);
    mBinding.include.ivTitleGank.setSelected(true);
    vpContent.setCurrentItem(0);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
    }
}
Also used : GankFragment(com.example.jingbin.cloudreader.ui.gank.GankFragment) MyFragmentPagerAdapter(com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter) ArrayList(java.util.ArrayList) OneFragment(com.example.jingbin.cloudreader.ui.one.OneFragment) BookFragment(com.example.jingbin.cloudreader.ui.book.BookFragment) GankFragment(com.example.jingbin.cloudreader.ui.gank.GankFragment) BookFragment(com.example.jingbin.cloudreader.ui.book.BookFragment) Fragment(android.support.v4.app.Fragment) OneFragment(com.example.jingbin.cloudreader.ui.one.OneFragment) ActionBar(android.support.v7.app.ActionBar)

Example 43 with ViewPager

use of android.support.v4.view.ViewPager in project Android-skin-support by ximsfei.

the class SlidingTabActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sliding_tab);
    for (String title : mTitles) {
        mFragments.add(SimpleCardFragment.getInstance(title));
    }
    View decorView = getWindow().getDecorView();
    ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
    mAdapter = new MyPagerAdapter(getSupportFragmentManager());
    vp.setAdapter(mAdapter);
    /** 默认 */
    SlidingTabLayout tabLayout_1 = ViewFindUtils.find(decorView, R.id.tl_1);
    /**自定义部分属性*/
    SlidingTabLayout tabLayout_2 = ViewFindUtils.find(decorView, R.id.tl_2);
    /** 字体加粗,大写 */
    SlidingTabLayout tabLayout_3 = ViewFindUtils.find(decorView, R.id.tl_3);
    /** tab固定宽度 */
    SlidingTabLayout tabLayout_4 = ViewFindUtils.find(decorView, R.id.tl_4);
    /** indicator固定宽度 */
    SlidingTabLayout tabLayout_5 = ViewFindUtils.find(decorView, R.id.tl_5);
    /** indicator圆 */
    SlidingTabLayout tabLayout_6 = ViewFindUtils.find(decorView, R.id.tl_6);
    /** indicator矩形圆角 */
    final SlidingTabLayout tabLayout_7 = ViewFindUtils.find(decorView, R.id.tl_7);
    /** indicator三角形 */
    SlidingTabLayout tabLayout_8 = ViewFindUtils.find(decorView, R.id.tl_8);
    /** indicator圆角色块 */
    SlidingTabLayout tabLayout_9 = ViewFindUtils.find(decorView, R.id.tl_9);
    /** indicator圆角色块 */
    SlidingTabLayout tabLayout_10 = ViewFindUtils.find(decorView, R.id.tl_10);
    tabLayout_1.setViewPager(vp);
    tabLayout_2.setViewPager(vp);
    tabLayout_2.setOnTabSelectListener(this);
    tabLayout_3.setViewPager(vp);
    tabLayout_4.setViewPager(vp);
    tabLayout_5.setViewPager(vp);
    tabLayout_6.setViewPager(vp);
    tabLayout_7.setViewPager(vp, mTitles);
    tabLayout_8.setViewPager(vp, mTitles, this, mFragments);
    tabLayout_9.setViewPager(vp);
    tabLayout_10.setViewPager(vp);
    vp.setCurrentItem(4);
    tabLayout_1.showDot(4);
    MsgView rtv_1_4 = tabLayout_1.getMsgView(4);
    if (rtv_1_4 != null) {
        if (rtv_1_4 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_1_4).setBackgroundColorResource(R.color.msg_background_color);
            ((SkinMsgView) rtv_1_4).setStrokeColorResource(R.color.msg_stroke_color);
        } else {
            rtv_1_4.setBackgroundColor(Color.parseColor("#6D8FB0"));
        }
    }
    tabLayout_3.showDot(4);
    tabLayout_2.showDot(4);
    tabLayout_2.showMsg(3, 5);
    tabLayout_2.setMsgMargin(3, 0, 10);
    MsgView rtv_2_3 = tabLayout_2.getMsgView(3);
    if (rtv_2_3 != null) {
        if (rtv_2_3 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_2_3).setBackgroundColorResource(R.color.msg_background_color);
            ((SkinMsgView) rtv_2_3).setStrokeColorResource(R.color.msg_stroke_color);
        } else {
            rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
        }
    }
    tabLayout_2.showMsg(5, 5);
    tabLayout_2.setMsgMargin(5, 0, 10);
//        tabLayout_7.setOnTabSelectListener(new OnTabSelectListener() {
//            @Override
//            public void onTabSelect(int position) {
//                Toast.makeText(mContext, "onTabSelect&position--->" + position, Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onTabReselect(int position) {
//                mFragments.add(SimpleCardFragment.getInstance("后端"));
//                mAdapter.notifyDataSetChanged();
//                tabLayout_7.addNewTab("后端");
//            }
//        });
}
Also used : SkinMsgView(skin.support.flycotablayout.widget.SkinMsgView) SkinMsgView(skin.support.flycotablayout.widget.SkinMsgView) MsgView(com.flyco.tablayout.widget.MsgView) SlidingTabLayout(com.flyco.tablayout.SlidingTabLayout) SkinMsgView(skin.support.flycotablayout.widget.SkinMsgView) MsgView(com.flyco.tablayout.widget.MsgView) View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Example 44 with ViewPager

use of android.support.v4.view.ViewPager in project Android-skin-support by ximsfei.

the class MainActivity method configFragments.

private void configFragments() {
    List<Fragment> list = new ArrayList<>();
    list.add(new FirstFragment());
    list.add(new MiddleFragment());
    list.add(new LastFragment());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    viewPager.setAdapter(new TabFragmentPagerAdapter(getSupportFragmentManager(), list));
    List<String> listTitle = new ArrayList<>();
    listTitle.add("系统组件");
    listTitle.add("自定义View");
    listTitle.add("第三方库控件");
    mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
    viewPager.setAdapter(mTabFragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}
Also used : MiddleFragment(com.ximsfei.skindemo.tab.MiddleFragment) LastFragment(com.ximsfei.skindemo.tab.LastFragment) FirstFragment(com.ximsfei.skindemo.tab.FirstFragment) TabLayout(android.support.design.widget.TabLayout) ArrayList(java.util.ArrayList) TabFragmentPagerAdapter(com.ximsfei.skindemo.tab.TabFragmentPagerAdapter) LastFragment(com.ximsfei.skindemo.tab.LastFragment) FirstFragment(com.ximsfei.skindemo.tab.FirstFragment) Fragment(android.support.v4.app.Fragment) MiddleFragment(com.ximsfei.skindemo.tab.MiddleFragment) ViewPager(android.support.v4.view.ViewPager)

Example 45 with ViewPager

use of android.support.v4.view.ViewPager in project Android-skin-support by ximsfei.

the class MaterialDesignActivity method configFragments.

private void configFragments() {
    List<Fragment> list = new ArrayList<>();
    list.add(new MDFirstFragment());
    //        list.add(new MiddleFragment());
    //        list.add(new LastFragment());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    List<String> listTitle = new ArrayList<>();
    listTitle.add("系统组件");
    //        listTitle.add("自定义View");
    //        listTitle.add("第三方库控件");
    mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
    viewPager.setAdapter(mTabFragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}
Also used : TabLayout(android.support.design.widget.TabLayout) MDFirstFragment(com.ximsfei.skindemo.mdtab.MDFirstFragment) ArrayList(java.util.ArrayList) TabFragmentPagerAdapter(com.ximsfei.skindemo.tab.TabFragmentPagerAdapter) Fragment(android.support.v4.app.Fragment) MDFirstFragment(com.ximsfei.skindemo.mdtab.MDFirstFragment) ViewPager(android.support.v4.view.ViewPager)

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