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


Java LinearLayoutManager.scrollToPositionWithOffset方法代码示例

本文整理汇总了Java中android.support.v7.widget.LinearLayoutManager.scrollToPositionWithOffset方法的典型用法代码示例。如果您正苦于以下问题:Java LinearLayoutManager.scrollToPositionWithOffset方法的具体用法?Java LinearLayoutManager.scrollToPositionWithOffset怎么用?Java LinearLayoutManager.scrollToPositionWithOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.LinearLayoutManager的用法示例。


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

示例1: onCreateViewHolder

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View layoutView = LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false);

    //create Recycler here
    MyRecyclerView recyclerView = (MyRecyclerView) layoutView.findViewById(R.id.horizontal_recycler_view);
    recyclerView.reboot(); //in case it's recycled

    // Create the right adapter for the recycler view
    HorizontalAdapter horizontalAdapter;
    horizontalAdapter = new HorizontalAdapter(recyclerView.getContext(), "", mTabNumber, mDarkTheme);

    // Set up the manager and adapter of the recycler view
    LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
    horizontalLayoutManager.scrollToPositionWithOffset(1, 0);
    recyclerView.setTag(0);
    recyclerView.setLayoutManager(horizontalLayoutManager);
    recyclerView.setAdapter(horizontalAdapter);
    recyclerView.setUp();

    return new ViewHolder(layoutView, recyclerView);
}
 
开发者ID:IdeaTrackerPlus,项目名称:IdeaTrackerPlus,代码行数:23,代码来源:ItemAdapter.java

示例2: scrollTo

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Utils.java

示例3: onLeftItemSelected

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onLeftItemSelected(int position, DishMenu menu) {
    int sum=0;
    for(int i = 0;i<position;i++){
        sum+=dishMenuList.get(i).getDishList().size()+1;
    }
    LinearLayoutManager layoutManager = (LinearLayoutManager) rightMenu.getLayoutManager();
    layoutManager.scrollToPositionWithOffset(sum,0);
    leftClickType = true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:MainActivity.java

示例4: onCreate

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    setContentView(R.layout.activity_recycler);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mRvPostLister = (RecyclerView) findViewById(R.id.rv_post_list);
    final LinearLayoutManager manager = new LinearLayoutManager(this);
    mRvPostLister.setLayoutManager(manager);
    mPostList = new ArrayList<>();
    for (int i = 0; i < 29; i++) {
        List<UserViewInfo> imgUrls = new ArrayList<>();
        UserViewInfo userViewInfo;
        Random ss=new Random();
        for (int j = 0; j <ss.nextInt(9); j++) {
            userViewInfo=new UserViewInfo(IMG_URL_LIST[j]);
            imgUrls.add(userViewInfo);
        }
        Post post = new Post("Am I handsome? Am I handsome? Am I handsome?", imgUrls);
        mPostList.add(post);
    }

    mNineImageAdapter = new PostAdapter(this, mPostList, NineGridImageView.STYLE_GRID);
    mRvPostLister.setAdapter(mNineImageAdapter);
    manager.scrollToPositionWithOffset(5, 0);
    mRvPostLister.post(new Runnable() {
        @Override
        public void run() {
            View view = manager.findViewByPosition(1);
            if (view != null) System.out.println(view.getMeasuredHeight());
        }
    });
}
 
开发者ID:yangchaojiang,项目名称:ZoomPreviewPicture,代码行数:34,代码来源:GridStyleActivity.java

示例5: getView

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public View getView(int position, View view, ViewGroup parent) {

    //Recycle made complicated with big text option
    if (view == null) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        view = inflater.inflate(R.layout.recycler_view_item, parent, false);
    }

    MyRecyclerView horizontal_recycler_view = (MyRecyclerView) view.findViewById(R.id.horizontal_recycler_view);
    horizontal_recycler_view.reboot(); //in case it's recycled

    // Get the text and id of the idea
    ArrayList<Pair<Integer, String>> ideas = mDbHelper.searchIdeas(subString);
    Pair<Integer, String> pair = ideas.get(position);

    // Create the right adapter for the recycler view
    HorizontalAdapter horizontalAdapter;
    horizontalAdapter = new HorizontalAdapter(horizontal_recycler_view.getContext(), pair.second, 4, mDarkTheme);

    // Set up the manager and adapter of the recycler view
    LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(horizontal_recycler_view.getContext(), LinearLayoutManager.HORIZONTAL, false);
    horizontalLayoutManager.scrollToPositionWithOffset(1, 0);
    horizontal_recycler_view.setTag(pair.first);
    horizontal_recycler_view.setLayoutManager(horizontalLayoutManager);
    horizontal_recycler_view.setAdapter(horizontalAdapter);
    horizontal_recycler_view.setUp();

    //return the entire view
    return view;
}
 
开发者ID:IdeaTrackerPlus,项目名称:IdeaTrackerPlus,代码行数:32,代码来源:SearchListAdapter.java

示例6: onCreateView

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public View onCreateView(
    @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  final View result = inflater.inflate(R.layout.flickr_photo_list, container, false);

  list = (RecyclerView) result.findViewById(R.id.flickr_photo_list);
  layoutManager = new LinearLayoutManager(getActivity());
  list.setLayoutManager(layoutManager);
  adapter = new FlickrPhotoListAdapter();
  list.setAdapter(adapter);

  preloadSizeProvider = new ViewPreloadSizeProvider<>();
  RecyclerViewPreloader<Photo> preloader =
      new RecyclerViewPreloader<>(
          GlideApp.with(this), adapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);
  list.addOnScrollListener(preloader);
  list.setItemViewCacheSize(0);

  if (currentPhotos != null) {
    adapter.setPhotos(currentPhotos);
  }

  final GlideRequests glideRequests = GlideApp.with(this);
  fullRequest = glideRequests
      .asDrawable()
      .centerCrop()
      .placeholder(new ColorDrawable(Color.GRAY));

  thumbRequest = glideRequests
      .asDrawable()
      .diskCacheStrategy(DiskCacheStrategy.DATA)
      .override(Api.SQUARE_THUMB_SIZE)
      .transition(withCrossFade());

  list.setRecyclerListener(new RecyclerView.RecyclerListener() {
    @Override
    public void onViewRecycled(RecyclerView.ViewHolder holder) {
      PhotoTitleViewHolder vh = (PhotoTitleViewHolder) holder;
      glideRequests.clear(vh.imageView);
    }
  });

  if (savedInstanceState != null) {
    int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
    int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
    layoutManager.scrollToPositionWithOffset(index, offset);
  }

  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:51,代码来源:FlickrPhotoList.java

示例7: postBindView

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void postBindView(BaseCell cell) {
    if (lSCell == null) {
        return;
    }

    recyclerView.setRecycledViewPool(lSCell.getRecycledViewPool());

    float[] starts = null;
    if (lSCell.cells != null && lSCell.cells.size() > 0) {
        starts = new float[lSCell.cells.size()];
        for (int i = 0; i < lSCell.cells.size(); i++) {
            starts[i] = totalDistance;

            BaseCell bc = lSCell.cells.get(i);
            if (bc.style != null && bc.style.margin.length > 0) {
                totalDistance = totalDistance + bc.style.margin[1] + bc.style.margin[3];
            }
            if (!Double.isNaN(lSCell.pageWidth)) {
                if (!Double.isNaN(bc.extras.optDouble("pageWidth"))) {
                    totalDistance += Style.dp2px(bc.extras.optDouble("pageWidth"));
                } else {
                    totalDistance += lSCell.pageWidth;
                }
            }
        }
    }
    totalDistance -= getScreenWidth();

    // calculate height of recycler view.
    ViewGroup.LayoutParams lp = recyclerView.getLayoutParams();
    if (!Double.isNaN(lSCell.pageHeight)) {
        lp.height = (int) (lSCell.pageHeight + 0.5);
    }
    recyclerView.setLayoutParams(lp);

    recyclerView.setAdapter(lSCell.adapter);

    if (lSCell.hasIndicator && totalDistance > 0) {
        setViewColor(indicator, lSCell.indicatorColor);
        setViewColor(indicatorContainer, lSCell.defaultIndicatorColor);
        indicatorContainer.setVisibility(VISIBLE);
    } else {
        indicatorContainer.setVisibility(GONE);
    }

    overScrollDecorator.setOnOverScrollListener(this);
    overScrollDecorator.setOnMotionEventListener(this);

    recyclerView.addOnScrollListener(onScrollListener);

    setBackgroundColor(lSCell.bgColor);

    if (lSCell.retainScrollState) {
        int position = computeFirstCompletelyVisibleItemPositionForScrolledX(starts);
        LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
        lm.scrollToPositionWithOffset(position,
                starts == null || starts.length <= position ? 0 : (int) (starts[position] - lSCell.currentDistance));
    }
    if (lSCell.scrollMarginLeft > 0 || lSCell.scrollMarginRight > 0) {
        setPadding(lSCell.scrollMarginLeft, 0, lSCell.scrollMarginRight, 0);
        setClipToPadding(false);
        setClipChildren(false);
    } else {
        setPadding(0, 0, 0, 0);
        setClipToPadding(true);
        setClipChildren(true);
    }
    recycleView(lSCell);
    bindHeaderView(lSCell.mHeader);
    bindFooterView(lSCell.mFooter);
}
 
开发者ID:alibaba,项目名称:Tangram-Android,代码行数:73,代码来源:LinearScrollView.java

示例8: scrollToPositionAtProgress

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
/**
 * Maps the touch (from 0..1) to the adapter position that should be visible.
 */
public String scrollToPositionAtProgress(float touchFraction) {
    int itemCount = getAdapter().getItemCount();
    if (itemCount == 0) {
        return "";
    }
    int spanCount = 1;
    int rowCount = itemCount;
    if (getLayoutManager() instanceof GridLayoutManager) {
        spanCount = ((GridLayoutManager) getLayoutManager()).getSpanCount();
        rowCount = (int) Math.ceil((double) rowCount / spanCount);
    }

    // Stop the scroller if it is scrolling
    stopScroll();

    getCurScrollState(mScrollPosState);

    float itemPos = itemCount * touchFraction;

    int availableScrollHeight = getAvailableScrollHeight(rowCount, mScrollPosState.rowHeight, 0);

    //The exact position of our desired item
    int exactItemPos = (int) (availableScrollHeight * touchFraction);

    //Scroll to the desired item. The offset used here is kind of hard to explain.
    //If the position we wish to scroll to is, say, position 10.5, we scroll to position 10,
    //and then offset by 0.5 * rowHeight. This is how we achieve smooth scrolling.
    LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
    layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / mScrollPosState.rowHeight,
            -(exactItemPos % mScrollPosState.rowHeight));

    if (!(getAdapter() instanceof SectionedAdapter)) {
        return "";
    }

    int posInt = (int) ((touchFraction == 1) ? itemPos - 1 : itemPos);

    SectionedAdapter sectionedAdapter = (SectionedAdapter) getAdapter();
    return sectionedAdapter.getSectionName(posInt);
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:44,代码来源:FastScrollRecyclerView.java

示例9: scrollToRowAtIndexPath

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
public void scrollToRowAtIndexPath(SLIndexPath indexPath) {
    int position = indexPathToPosition(indexPath);
    LinearLayoutManager manager = (LinearLayoutManager) tableView.getLayoutManager();
    manager.scrollToPositionWithOffset(position, 0);

}
 
开发者ID:xiaoshanlin000,项目名称:SLTableView,代码行数:7,代码来源:SLTableViewAdapter.java

示例10: bindEvenListener

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void bindEvenListener(@Nullable Bundle savedInstanceState) {
    super.bindEvenListener(savedInstanceState);
    allowSwipeBack(false);
    unbinder = ButterKnife.bind(this, viewDelegate.getRootView());
    mDataManager = new DataManager();
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mDatas = new ArrayList<>();

    final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance());
    GlideRequest<Drawable> fullRequest = glideRequests
            .asDrawable()
            .centerCrop()
            .placeholder(new ColorDrawable(Color.GRAY));

    GlideRequest<Drawable> thumbRequest = glideRequests
            .asDrawable()
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .transition(withCrossFade());

    mAdapter = new CollectionAdapter(fullRequest, thumbRequest);
    mAdapter.setOnLoadMoreListener(this, mRecyclerView);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);

    ViewPreloadSizeProvider<Collection> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    RecyclerViewPreloader<Collection> preloader =
            new RecyclerViewPreloader<>(
                    GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);

    mRecyclerView.addOnScrollListener(preloader);
    mRecyclerView.setItemViewCacheSize(0);

    mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() {
        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            BaseViewHolder holder1 = (BaseViewHolder) holder;
            AppCompatImageView imageView = holder1.getView(R.id.item_image);
            if (null != imageView) {
                glideRequests.clear(imageView);
            }
        }
    });

    if (null != savedInstanceState) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
        mLayoutManager.scrollToPositionWithOffset(index, offset);
    }

    RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
        @Override
        public void accept(Object o) throws Exception {
            mSwipeRefreshLayout.setVisibility(View.VISIBLE);
            mStateView.setVisibility(View.GONE);
            startRefresh();
        }
    });
}
 
开发者ID:alphater,项目名称:garras,代码行数:61,代码来源:UserCollectionFragment.java

示例11: scrollToPositionAtProgress

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
/**
 * <p>Maps the touch (from 0..1) to the adapter position that should be visible.</p>
 * <p/>
 * <p>Override in each subclass of this base class.</p>
 */
public String scrollToPositionAtProgress(float touchFraction) {
    int itemCount = getAdapter().getItemCount();
    if (itemCount == 0) {
        return "";
    }
    int spanCount = 1;
    int rowCount = itemCount;
    if (getLayoutManager() instanceof GridLayoutManager) {
        spanCount = ((GridLayoutManager) getLayoutManager()).getSpanCount();
        rowCount = (int) Math.ceil((double) rowCount / spanCount);
    }

    // Stop the scroller if it is scrolling
    stopScroll();

    getCurScrollState(scrollPositionState);

    float itemPos = itemCount * touchFraction;

    int availableScrollHeight = getAvailableScrollHeight(rowCount, scrollPositionState.rowHeight);

    //The exact position of our desired item
    int exactItemPos = (int) (availableScrollHeight * touchFraction);

    //Scroll to the desired item. The offset used here is kind of hard to explain.
    //If the position we wish to scroll to is, say, position 10.5, we scroll to position 10,
    //and then offset by 0.5 * rowHeight. This is how we achieve smooth scrolling.
    LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
    layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / scrollPositionState.rowHeight,
            -(exactItemPos % scrollPositionState.rowHeight));

    if (!(getAdapter() instanceof SectionedAdapter)) {
        return "";
    }

    int posInt = (int) ((touchFraction == 1) ? itemPos - 1 : itemPos);

    SectionedAdapter sectionedAdapter = (SectionedAdapter) getAdapter();
    return sectionedAdapter.getSectionName(posInt);
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:46,代码来源:FastScrollRecyclerView.java

示例12: bindEvenListener

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void bindEvenListener(@Nullable Bundle savedInstanceState) {
    super.bindEvenListener(savedInstanceState);
    allowSwipeBack(false);
    unbinder = ButterKnife.bind(this, viewDelegate.getRootView());
    mDataManager = new DataManager();
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setRefreshing(false);

    final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance());
    GlideRequest<Drawable> fullRequest = glideRequests
            .asDrawable()
            .centerCrop()
            .placeholder(new ColorDrawable(Color.GRAY));

    GlideRequest<Drawable> thumbRequest = glideRequests
            .asDrawable()
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .transition(withCrossFade());

    mAdapter = new UserAdapter(fullRequest, thumbRequest);
    mAdapter.setOnLoadMoreListener(this, mRecyclerView);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);

    ViewPreloadSizeProvider<User> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    RecyclerViewPreloader<User> preloader =
            new RecyclerViewPreloader<>(
                    GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);

    mRecyclerView.addOnScrollListener(preloader);
    mRecyclerView.setItemViewCacheSize(0);

    mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() {
        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            BaseViewHolder holder1 = (BaseViewHolder) holder;
            AppCompatImageView imageView = holder1.getView(R.id.item_image);
            if (null != imageView) {
                glideRequests.clear(imageView);
            }
        }
    });

    if (null != savedInstanceState) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
        mLayoutManager.scrollToPositionWithOffset(index, offset);
    }

    RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
        @Override
        public void accept(Object o) throws Exception {
            mSwipeRefreshLayout.setVisibility(View.VISIBLE);
            mStateView.setVisibility(View.GONE);
            startRefresh();
        }
    });
}
 
开发者ID:alphater,项目名称:garras,代码行数:61,代码来源:SearchUserFragment.java

示例13: bindEvenListener

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void bindEvenListener(@Nullable Bundle savedInstanceState) {
    super.bindEvenListener(savedInstanceState);
    allowSwipeBack(false);
    unbinder = ButterKnife.bind(this, viewDelegate.getRootView());
    mDataManager = new DataManager();
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setRefreshing(false);
    mDatas = new ArrayList<>();

    final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance());
    GlideRequest<Drawable> fullRequest = glideRequests
            .asDrawable()
            .centerCrop()
            .placeholder(new ColorDrawable(Color.GRAY));

    GlideRequest<Drawable> thumbRequest = glideRequests
            .asDrawable()
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .transition(withCrossFade());

    mAdapter = new PhotoAdapter(fullRequest, thumbRequest);
    mAdapter.setOnLoadMoreListener(this, mRecyclerView);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);

    ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    RecyclerViewPreloader<Photos> preloader =
            new RecyclerViewPreloader<>(
                    GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);

    mRecyclerView.addOnScrollListener(preloader);
    mRecyclerView.setItemViewCacheSize(0);

    mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() {
        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            BaseViewHolder holder1 = (BaseViewHolder) holder;
            AppCompatImageView imageView = holder1.getView(R.id.item_image);
            if (null != imageView) {
                glideRequests.clear(imageView);
            }
        }
    });

    if (null != savedInstanceState) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
        mLayoutManager.scrollToPositionWithOffset(index, offset);
    }
    RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
        @Override
        public void accept(Object o) throws Exception {
            mSwipeRefreshLayout.setVisibility(View.VISIBLE);
            mStateView.setVisibility(View.GONE);
            startRefresh();
        }
    });
}
 
开发者ID:alphater,项目名称:garras,代码行数:61,代码来源:SearchPhotoFragment.java

示例14: bindEvenListener

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void bindEvenListener(@Nullable Bundle savedInstanceState) {
    super.bindEvenListener(savedInstanceState);
    allowSwipeBack(false);
    unbinder = ButterKnife.bind(this, viewDelegate.getRootView());
    mDataManager = new DataManager();
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setRefreshing(false);
    mDatas = new ArrayList<>();

    final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance());
    GlideRequest<Drawable> fullRequest = glideRequests
            .asDrawable()
            .centerCrop()
            .placeholder(new ColorDrawable(Color.GRAY));

    GlideRequest<Drawable> thumbRequest = glideRequests
            .asDrawable()
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .transition(withCrossFade());

    mAdapter = new CollectionAdapter(fullRequest, thumbRequest);
    mAdapter.setOnLoadMoreListener(this, mRecyclerView);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);

    ViewPreloadSizeProvider<Collection> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    RecyclerViewPreloader<Collection> preloader =
            new RecyclerViewPreloader<>(
                    GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);

    mRecyclerView.addOnScrollListener(preloader);
    mRecyclerView.setItemViewCacheSize(0);

    mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() {
        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            BaseViewHolder holder1 = (BaseViewHolder) holder;
            AppCompatImageView imageView = holder1.getView(R.id.item_image);
            if (null != imageView) {
                glideRequests.clear(imageView);
            }
        }
    });

    if (null != savedInstanceState) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
        mLayoutManager.scrollToPositionWithOffset(index, offset);
    }
    RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
        @Override
        public void accept(Object o) throws Exception {
            mSwipeRefreshLayout.setVisibility(View.VISIBLE);
            mStateView.setVisibility(View.GONE);
            startRefresh();
        }
    });
}
 
开发者ID:alphater,项目名称:garras,代码行数:61,代码来源:SearchCollectionFragment.java

示例15: bindEvenListener

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void bindEvenListener(@Nullable Bundle savedInstanceState) {
    super.bindEvenListener(savedInstanceState);
    allowSwipeBack(false);
    unbinder = ButterKnife.bind(this, viewDelegate.getRootView());
    if (null == getActivity()) return;
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
    mRefreshBroadcastReceiver = new RefreshBroadcastReceiver();
    mLocalBroadcastManager.registerReceiver(mRefreshBroadcastReceiver, new IntentFilter("refresh"));

    mDataManager = new DataManager();
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mDatas = new ArrayList<>();

    final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance());
    GlideRequest<Drawable> fullRequest = glideRequests
            .asDrawable()
            .centerCrop()
            .placeholder(new ColorDrawable(Color.GRAY));

    GlideRequest<Drawable> thumbRequest = glideRequests
            .asDrawable()
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .transition(withCrossFade());

    mAdapter = new PhotoAdapter(fullRequest, thumbRequest);
    mAdapter.setOnLoadMoreListener(this, mRecyclerView);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);

    ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    RecyclerViewPreloader<Photos> preloader =
            new RecyclerViewPreloader<>(
                    GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);

    mRecyclerView.addOnScrollListener(preloader);
    mRecyclerView.setItemViewCacheSize(0);

    mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() {
        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            BaseViewHolder holder1 = (BaseViewHolder) holder;
            AppCompatImageView imageView = holder1.getView(R.id.item_image);
            if (null != imageView) {
                glideRequests.clear(imageView);
            }
        }
    });

    RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
        @Override
        public void accept(Object o) throws Exception {
            mSwipeRefreshLayout.setVisibility(View.VISIBLE);
            mStateView.setVisibility(View.GONE);
            startRefresh();
        }
    });
    if (null != savedInstanceState) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
        mLayoutManager.scrollToPositionWithOffset(index, offset);
    }
}
 
开发者ID:alphater,项目名称:garras,代码行数:65,代码来源:FeaturedFragment.java


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