• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PagerSnapHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ExcessiveAttemptsException类代码示例发布时间:2022-05-21
下一篇:
Java Shard类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap