本文整理汇总了Java中android.support.v7.widget.PagerSnapHelper类的典型用法代码示例。如果您正苦于以下问题:Java PagerSnapHelper类的具体用法?Java PagerSnapHelper怎么用?Java PagerSnapHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PagerSnapHelper类属于android.support.v7.widget包,在下文中一共展示了PagerSnapHelper类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onCreateView
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
@Override
protected View onCreateView() {
View root = LayoutInflater.from(getContext()).inflate(R.layout.fragment_pagerlayoutmanager, null);
ButterKnife.bind(this, root);
mQDItemDescription = QDDataManager.getInstance().getDescription(this.getClass());
initTopBar();
mRecyclerView = new RecyclerView(getContext());
mPagerLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerView.setLayoutManager(mPagerLayoutManager);
mRecyclerViewAdapter = new QDRecyclerViewAdapter();
mRecyclerViewAdapter.setItemCount(10);
mRecyclerView.setAdapter(mRecyclerViewAdapter);
mPagerWrap.addView(mRecyclerView);
// PagerSnapHelper每次只能滚动一个item;用LinearSnapHelper则可以一次滚动多个,并最终保证定位
// mSnapHelper = new LinearSnapHelper();
mSnapHelper = new PagerSnapHelper();
mSnapHelper.attachToRecyclerView(mRecyclerView);
return root;
}
开发者ID:coopese,项目名称:qmui,代码行数:22,代码来源:QDSnapHelperFragment.java
示例2: initPagerView
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
private void initPagerView() {
pagerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
pagerView.setHasFixedSize(true);
pagerView.setAdapter(pagerAdapter);
new PagerSnapHelper().attachToRecyclerView(pagerView);
pagerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
int index = ((LinearLayoutManager) pagerView.getLayoutManager()).findFirstVisibleItemPosition();
View pagerItemView = ImageGalleryView.this.pagerView.getLayoutManager().findViewByPosition(index);
index = ((LinearLayoutManager) pagerIndicatorView.getLayoutManager()).findFirstVisibleItemPosition();
View pagerIndicatorItemView = pagerIndicatorView.getLayoutManager().findViewByPosition(index);
float offset = 1f * dx / (pagerView.getAdapter().getItemCount() * pagerItemView.getWidth());
pagerIndicatorFrameView.setTranslationX(pagerIndicatorFrameView.getTranslationX()
+ offset * pagerIndicatorItemView.getWidth() * pagerIndicatorView.getAdapter().getItemCount());
}
});
}
开发者ID:Shopify,项目名称:mobile-buy-sdk-android,代码行数:21,代码来源:ImageGalleryView.java
示例3: onCreateRecyclerView
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
@Override
public void onCreateRecyclerView(Bundle savedInstanceState) {
int backgroundColor = 0xFF665F30;
Context context = this;
recyclerView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
recyclerView.setBackgroundColor(backgroundColor);
SimpleViewAdapter adapter = new SimpleViewAdapter(5, R.layout.item_view_pager_page);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
// add pager behavior
PagerSnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
// pager indicator
recyclerView.addItemDecoration(new LinePagerIndicatorDecoration());
}
开发者ID:bleeding182,项目名称:recyclerviewItemDecorations,代码行数:21,代码来源:ViewPagerActivity.java
示例4: toViewPager
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
/**
* transform to ViewPager
*
* @param recyclerView {@link RecyclerView}
* @param orientation the orientation of Linearlayout
*/
public static void toViewPager(RecyclerView recyclerView
, @LinearLayoutCompat.OrientationMode int orientation) {
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()
, orientation, false));
new PagerSnapHelper().attachToRecyclerView(recyclerView);
}
开发者ID:arjinmc,项目名称:ExpandRecyclerView,代码行数:13,代码来源:RecyclerViewStyleHelper.java
示例5: init
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
private void init(Context context, @Nullable AttributeSet attrs) {
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MetalRecyclerViewPager, 0, 0);
itemMargin = (int) typedArray.getDimension(R.styleable.MetalRecyclerViewPager_itemMargin, 0f);
typedArray.recycle();
}
setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(this);
}
开发者ID:solankiherry,项目名称:recyclviewpagger,代码行数:12,代码来源:MetalRecyclerViewPager.java
示例6: RecyclerViewPager
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
public RecyclerViewPager(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
setLayoutManager(mLayoutManager);
new PagerSnapHelper().attachToRecyclerView(this);
final float density = context.getResources().getDisplayMetrics().density;
mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
mTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
}
开发者ID:thaihuynhxyz,项目名称:recycler-view-pager,代码行数:13,代码来源:RecyclerViewPager.java
示例7: initSnapHelper
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
/**
* 初始化SnapHelper
*
* @param helper
*/
public void initSnapHelper(int helper) {
switch (helper) {
case GalleryRecyclerView.LinearySnapHelper:
mLinearySnapHelper = new LinearSnapHelper();
mLinearySnapHelper.attachToRecyclerView(mGalleryRecyclerView);
break;
case GalleryRecyclerView.PagerSnapHelper:
mPagerSnapHelper = new PagerSnapHelper();
mPagerSnapHelper.attachToRecyclerView(mGalleryRecyclerView);
break;
}
}
开发者ID:ryanlijianchang,项目名称:Recyclerview-Gallery,代码行数:18,代码来源:ScrollManager.java
示例8: onBindViewHolder
import android.support.v7.widget.PagerSnapHelper; //导入依赖的package包/类
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
HomeGroup snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
holder.recyclerView.setOnFlingListener(null);
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new PagerSnapHelper().attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext()));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
HomeItemAdapter itemAdapter = new HomeItemAdapter(mContext, snap.getCardSize(), snap.getApps());
holder.recyclerView.setAdapter(itemAdapter);
itemAdapter.setOnItemClickListener(new HomeItemAdapter.OnItemClickListener() {
@Override
public void itemClick(HomeItem item, int Position) {
if(mContext instanceof HomeActivity) {
if(item.isWebView()) {
((HomeActivity) mContext).attachFragment(WebFragment.newInstance(item.getUrl(), item.getName()), true);
} else {
((HomeActivity) mContext).attachFragment(FirebaseListFragment.newInstance(item.getUrl(), item.getExtra()), true);
}
}
}
});
}
开发者ID:mangoblogger,项目名称:MangoBloggerAndroidApp,代码行数:45,代码来源:HomeBaseAdapter.java
注:本文中的android.support.v7.widget.PagerSnapHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论