当前位置: 首页>>代码示例>>Java>>正文


Java PagerAdapter类代码示例

本文整理汇总了Java中android.support.v4.view.PagerAdapter的典型用法代码示例。如果您正苦于以下问题:Java PagerAdapter类的具体用法?Java PagerAdapter怎么用?Java PagerAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PagerAdapter类属于android.support.v4.view包,在下文中一共展示了PagerAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: defaultUltraViewPager

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
/**
 *
 */
private void defaultUltraViewPager(){
    UltraViewPager ultraViewPager = (UltraViewPager)findViewById(R.id.ultra_viewpager);
    ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL);
    //initialize UltraPagerAdapter,and add child view to UltraViewPager
    PagerAdapter adapter = new UltraPagerAdapter(false);
    ultraViewPager.setAdapter(adapter);

    //initialize built-in indicator
    ultraViewPager.initIndicator();
    //set style of indicators
    ultraViewPager.getIndicator()
            .setOrientation(UltraViewPager.Orientation.HORIZONTAL)
            .setFocusColor(Color.GREEN)
            .setNormalColor(Color.WHITE)
            .setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));
    //set the alignment
    ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    //construct built-in indicator, and add it to  UltraViewPager
    ultraViewPager.getIndicator().build();

    //set an infinite loop
    ultraViewPager.setInfiniteLoop(true);
    //enable auto-scroll mode
    ultraViewPager.setAutoScroll(2000);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:PagerActivity.java

示例2: initView

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void initView() {
    PagerAdapter adapter = mViewPager.getAdapter();
    if (autoHide) {
        if (adapter == null) {
            setVisibility(INVISIBLE);
        } else {
            setVisibility(VISIBLE);
            setText((mViewPager.getCurrentItem() + 1) + "/" + adapter.getCount());
        }
    } else {
        if (adapter == null) {
        } else {
            setText((mViewPager.getCurrentItem() + 1) + "/" + adapter.getCount());
        }
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:17,代码来源:TextIndicator.java

示例3: setAdapter

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setAdapter(PagerAdapter adapter) {
    wrappedPagerAdapter = adapter;
    //若设置的 adapter 不为空则对其进行包装
    wrapperPagerAdapter = (wrappedPagerAdapter == null) ? null : new AutoScrollPagerAdapter(adapter);
    super.setAdapter(wrapperPagerAdapter);  //为viewPager设置的是包装的adapter
    if (adapter != null && adapter.getCount() != 0) {
        post(new Runnable() {
            @Override
            public void run() {
                setCurrentItem(0, false);
            }
        });
    }
    startAutoScroll();
}
 
开发者ID:haihaio,项目名称:AmenEye,代码行数:17,代码来源:AutoScrollViewPager.java

示例4: setViewPager

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:17,代码来源:TabPageIndicator.java

示例5: notifyDataSetChanged

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
public void notifyDataSetChanged() {
    mTabLayout.removeAllViews();
    PagerAdapter adapter = mViewPager.getAdapter();
    IconPagerAdapter iconAdapter = null;
    if (adapter instanceof IconPagerAdapter) {
        iconAdapter = (IconPagerAdapter)adapter;
    }
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        CharSequence title = adapter.getPageTitle(i);
        if (title == null) {
            title = EMPTY_TITLE;
        }
        int iconResId = 0;
        if (iconAdapter != null) {
            iconResId = iconAdapter.getIconResId(i);
        }
        addTab(i, title, iconResId);
    }
    if (mSelectedTabIndex > count) {
        mSelectedTabIndex = count - 1;
    }
    setCurrentItem(mSelectedTabIndex);
    requestLayout();
}
 
开发者ID:fikyair,项目名称:musicplayer,代码行数:26,代码来源:TabPageIndicator.java

示例6: setAdapter

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setAdapter(PagerAdapter adapter) {
    if (adapter != null) {
        if (pagerAdapter == null || pagerAdapter.getAdapter() != adapter) {
            pagerAdapter = new UltraViewPagerAdapter(adapter);
            pagerAdapter.setCenterListener(this);
            pagerAdapter.setEnableLoop(enableLoop);
            pagerAdapter.setMultiScrRatio(multiScrRatio);
            needsMeasurePage = true;
            constrainLength = 0;
            super.setAdapter(pagerAdapter);
        }
    } else {
        super.setAdapter(adapter);
    }
}
 
开发者ID:alibaba,项目名称:UltraViewPager,代码行数:17,代码来源:UltraViewPagerView.java

示例7: setViewPager

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager view) {
	Logger.d("set ViewPager");
	if (mViewPager == view) {
		return;
	}
	if (mViewPager != null) {
		mViewPager.setOnPageChangeListener(null);
	}
	final PagerAdapter adapter = view.getAdapter();
	if (adapter == null) {
		throw new IllegalStateException("ViewPager does not have adapter instance.");
	}
	mViewPager = view;
	view.setOnPageChangeListener(this);
	notifyDataSetChanged();
}
 
开发者ID:iPanelkegy,项目名称:MobileMedia,代码行数:18,代码来源:UnderLinePageIndicator.java

示例8: setViewPager

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:17,代码来源:LVCustomViewPagerIndicator.java

示例9: bind

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private static void bind(ViewPager container, final ItemView itemView, final List<?> datas, final OnItemClickListener<?> onItemClickListener) {
    PagerAdapter adapter;
    if (datas != null && !datas.isEmpty()) {
        adapter = container.getAdapter();
        if(adapter == null) {
            // initialize, adapter is only set once !!!
            container.setAdapter(adapter = new CommonPagerAdapter<Object>(container.getContext(), itemView.layoutRes(), (List<Object>)datas) {
                @Override
                protected void convert(ViewHolder holder, Object data, int position) {
                    DataBindingUtil.bind(holder.itemView).setVariable(itemView.bindingVariable(), data);
                }
            });

            ((CommonPagerAdapter<Object>)adapter).setOnItemClickListener((OnItemClickListener<Object>)onItemClickListener);
        }

        adapter.notifyDataSetChanged();
    }
}
 
开发者ID:fashare2015,项目名称:MVVM-JueJin,代码行数:20,代码来源:ViewPagerAdapter.java

示例10: populateTabStrip

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void populateTabStrip() {
  final PagerAdapter adapter = viewPager.getAdapter();

  for (int i = 0; i < adapter.getCount(); i++) {

    final View tabView = (tabProvider == null)
        ? createDefaultTabView(adapter.getPageTitle(i))
        : tabProvider.createTabView(tabStrip, i, adapter);

    if (tabView == null) {
      throw new IllegalStateException("tabView is null.");
    }

    if (distributeEvenly) {
      LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
      lp.width = 0;
      lp.weight = 1;
    }

    if (internalTabClickListener != null) {
      tabView.setOnClickListener(internalTabClickListener);
    }

    tabStrip.addView(tabView);

    if (i == viewPager.getCurrentItem()) {
      tabView.setSelected(true);
    }

  }
}
 
开发者ID:devzwy,项目名称:KUtils,代码行数:32,代码来源:SmartTabLayout.java

示例11: notifyDataSetChanged

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
public void notifyDataSetChanged() {
    this.mTabLayout.removeAllViews();
    PagerAdapter adapter = this.mViewPager.getAdapter();
    IconPagerAdapter iconAdapter = null;
    if (adapter instanceof IconPagerAdapter) {
        iconAdapter = (IconPagerAdapter) adapter;
    }
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        CharSequence title = adapter.getPageTitle(i);
        if (title == null) {
            title = EMPTY_TITLE;
        }
        int iconResId = 0;
        if (iconAdapter != null) {
            iconResId = iconAdapter.getIconResId(i);
        }
        addTab(i, title, iconResId);
    }
    if (this.mSelectedTabIndex > count) {
        this.mSelectedTabIndex = count - 1;
    }
    setCurrentItem(this.mSelectedTabIndex);
    requestLayout();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:26,代码来源:TabPageIndicator.java

示例12: scrollOnce

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
/**
 * scroll only once
 */
public void scrollOnce() {
    PagerAdapter adapter = getAdapter();
    int currentItem = getCurrentItem();
    int totalCount;
    if (adapter == null || (totalCount = adapter.getCount()) <= 1) {
        return;
    }

    int nextItem = (direction == LEFT) ? --currentItem : ++currentItem;
    if (nextItem < 0) {
        if (isCycle) {
            setCurrentItem(totalCount - 1, isBorderAnimation);
        }
    } else if (nextItem == totalCount) {
        if (isCycle) {
            setCurrentItem(0, isBorderAnimation);
        }
    } else {
        setCurrentItem(nextItem, true);
    }
}
 
开发者ID:tranleduy2000,项目名称:text_converter,代码行数:25,代码来源:AutoScrollViewPager.java

示例13: setupWithViewPager

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void setupWithViewPager(@NonNull ViewPager viewPager) {
    mViewPager = viewPager;

    PagerAdapter adapter = viewPager.getAdapter();
    if (adapter == null) {
        throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
    }

    setTabsFromPagerAdapter(adapter);

    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        public void onPageSelected(int position) {
            if (!mScrollingByManual) {
                smoothScrollToPosition(mCircularTabLayoutAdapter.moveToPosition(position));
            }
            mScrollingByManual = false;
        }
    });
}
 
开发者ID:sanyuzhang,项目名称:CircularViewPager,代码行数:20,代码来源:CircularTabLayout.java

示例14: setAdapter

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setAdapter(PagerAdapter adapter) {
    if (adapter instanceof QMUIPagerAdapter) {
        super.setAdapter(new WrapperPagerAdapter((QMUIPagerAdapter) adapter));
    } else {
        super.setAdapter(adapter);
    }
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:9,代码来源:QMUIViewPager.java

示例15: listenToAdapterChanges

import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void listenToAdapterChanges(PagerAdapter pagerAdapter) {
    if (adapter != null) {
        adapter.unregisterDataSetObserver(adapterObserver);
    }
    if (pagerAdapter == null) {
        Log.e(TAG, "listenToAdapterChanges - pager adapter is null. can't register");
        return;
    }
    this.adapter = pagerAdapter;
    this.adapter.registerDataSetObserver(adapterObserver);
    notifyDatasetChanged();
}
 
开发者ID:Crysis21,项目名称:PagerTabIndicator,代码行数:13,代码来源:PagerTabsIndicator.java


注:本文中的android.support.v4.view.PagerAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。