本文整理汇总了Java中android.support.v4.view.PagerAdapter.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java PagerAdapter.getCount方法的具体用法?Java PagerAdapter.getCount怎么用?Java PagerAdapter.getCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.PagerAdapter
的用法示例。
在下文中一共展示了PagerAdapter.getCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPageScrolled
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// The documentation says that `getPageWidth(...)` returns the fraction of the _measured_ width that that page takes up. However, the code seems to
// use the width so we will here too.
final int width = getWidth();
PagerAdapter adapter = RtlViewPager.super.getAdapter();
if (isRtl() && adapter != null) {
int count = adapter.getCount();
int remainingWidth = (int) (width * (1 - adapter.getPageWidth(position))) + positionOffsetPixels;
while (position < count && remainingWidth > 0) {
position += 1;
remainingWidth -= (int) (width * adapter.getPageWidth(position));
}
position = count - position - 1;
positionOffsetPixels = -remainingWidth;
positionOffset = positionOffsetPixels / (width * adapter.getPageWidth(position));
}
mListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
}
示例2: 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);
}
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: notifyDataSetChanged
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
public void notifyDataSetChanged() {
PagerAdapter adapter = this.mViewPager.getAdapter();
int count = adapter.getCount();
if (count != 0) {
int width = TAB_MARGIN;
for (int i = 0; i < count; i++) {
width += getTabWidth(adapter.getPageTitle(i)) + TAB_MARGIN;
}
this.mMeanWidth = -1;
if (this.mLayoutWidh > width && count <= 7) {
this.mMeanWidth = (this.mLayoutWidh - (TAB_MARGIN * (count + 1))) / count;
}
super.notifyDataSetChanged();
}
}
示例7: notifyDataSetChanged
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
public void notifyDataSetChanged() {
PagerAdapter adapter = this.mViewPager.getAdapter();
int count = adapter.getCount();
if (count != 0) {
int width = TAB_MARGIN;
for (int i = 0; i < count; i++) {
width += getTabWidth(adapter.getPageTitle(i)) + TAB_MARGIN;
}
this.mMeanWidth = -1;
if (this.mLayoutWidth > width && count <= 7) {
this.mMeanWidth = this.mLayoutWidth / count;
}
super.notifyDataSetChanged();
}
}
示例8: setAdapter
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
public PagerAdapter setAdapter(final PagerAdapter adapter) {
// If adapter count bigger then 2 need to set InfiniteCyclePagerAdapter
if (adapter != null && adapter.getCount() >= MIN_CYCLE_COUNT) {
mItemCount = adapter.getCount();
mInfiniteCyclePagerAdapter = new InfiniteCyclePagerAdapter(adapter);
mInfiniteCyclePagerAdapter.setOnNotifyDataSetChangedListener(this);
return mInfiniteCyclePagerAdapter;
} else {
if (mInfiniteCyclePagerAdapter != null) {
mInfiniteCyclePagerAdapter.setOnNotifyDataSetChangedListener(null);
mInfiniteCyclePagerAdapter = null;
}
return adapter;
}
}
示例9: 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);
}
}
}
示例10: notifyDataSetChanged
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
public void notifyDataSetChanged() {
selectedPosition = 0;
titles.clear();
PagerAdapter adapter = mViewPager.getAdapter();
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
titles.add(adapter.getPageTitle(i).toString());
}
invalidate();
}
示例11: isScrolledAtEnd
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
/**
*/
@Override
public boolean isScrolledAtEnd() {
if (mScrollableView.getChildCount() == 0) {
return true;
}
final PagerAdapter adapter = mScrollableView.getAdapter();
return adapter == null || adapter.getCount() == 0 || mScrollableView.getCurrentItem() == (adapter.getCount() - 1);
}
示例12: onViewPagerCreated
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
@Override
public void onViewPagerCreated() {
PagerAdapter adapter = vViewPager.getAdapter();
if (adapter == null)
return;
if (!setCurrentDay) {
int idx = getTimetable().getDayIndexIn(0);
if (idx != -1 && adapter.getCount() != 0) {
vViewPager.setCurrentItem(idx);
setCurrentDay = true;
}
}
}
示例13: getCurrentItem
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
@Override
public int getCurrentItem() {
int item = super.getCurrentItem();
PagerAdapter adapter = super.getAdapter();
if (adapter != null && isRtl()) {
item = adapter.getCount() - item - 1;
}
return item;
}
示例14: setCurrentItem
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
@Override
public void setCurrentItem(int position, boolean smoothScroll) {
PagerAdapter adapter = super.getAdapter();
if (adapter != null && isRtl()) {
position = adapter.getCount() - position - 1;
}
super.setCurrentItem(position, smoothScroll);
}
示例15: notifyDataSetChanged
import android.support.v4.view.PagerAdapter; //导入方法依赖的package包/类
public void notifyDataSetChanged() {
tabsContainer.removeAllViews();
PagerAdapter adapter = pager.getAdapter();
tabCount = adapter.getCount();
for (int i = 0; i < tabCount; i++) {
if (adapter instanceof IconTabProvider) {
IconTabProvider ipa = ((IconTabProvider) adapter);
if (TEKST_DER_FADER_OVER_I_IKONER) {
int resId = ipa.getPageIconResId(i);
if (resId!=0) addIconTabBådeTekstOgBillede(i, resId, null, ipa.getPageContentDescription(i));
else {
String url = ipa.getPageIconUrl(i);
if (url!=null) addIconTabBådeTekstOgBillede(i, resId, url, ipa.getPageContentDescription(i));
else addTextTab(i, adapter.getPageTitle(i).toString());
}
} else {
addIconTab(i, ipa.getPageIconResId(i), ipa.getPageContentDescription(i));
}
} else {
addTextTab(i, adapter.getPageTitle(i).toString());
}
}
updateTabStyles();
getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
currentPosition = pager.getCurrentItem();
scrollToChild(currentPosition, 0);
}
});
if (TEKST_DER_FADER_OVER_I_IKONER) {
fadeTekstOgIkoner(currentPosition);
}
}