本文整理汇总了Java中android.support.v7.widget.PagerSnapHelper.attachToRecyclerView方法的典型用法代码示例。如果您正苦于以下问题:Java PagerSnapHelper.attachToRecyclerView方法的具体用法?Java PagerSnapHelper.attachToRecyclerView怎么用?Java PagerSnapHelper.attachToRecyclerView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.PagerSnapHelper
的用法示例。
在下文中一共展示了PagerSnapHelper.attachToRecyclerView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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());
}
示例3: 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;
}
}