/** * Returns information about the item that the recycler view is currently scrolled to. */ protected void getCurScrollState(ScrollPositionState stateOut) { stateOut.rowIndex = -1; stateOut.rowTopOffset = -1; stateOut.rowHeight = -1; // Return early if there are no items int rowCount = getAdapter().getItemCount(); if (rowCount == 0) { return; } View child = getChildAt(0); if (child == null) { return; } stateOut.rowIndex = getChildPosition(child); if (getLayoutManager() instanceof GridLayoutManager) { stateOut.rowIndex = stateOut.rowIndex / ((GridLayoutManager) getLayoutManager()).getSpanCount(); } if(child != null) { stateOut.rowTopOffset = getLayoutManager().getDecoratedTop(child); stateOut.rowHeight = child.getHeight(); } }
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager) { final GridLayoutManager gridManager = ((GridLayoutManager) manager); gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return (isHeader(position) || isFooter(position) || isRefreshHeader(position)) ? gridManager.getSpanCount() : 1; } }); } adapter.onAttachedToRecyclerView(recyclerView); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Set the adapter switch (mode) { case GRID: binding.list.setLayoutManager(new GridLayoutManager(getActivity(), 4)); break; case LIST: binding.list.setLayoutManager(new LinearLayoutManager(getActivity())); break; case TILE: binding.list.setLayoutManager(new GridLayoutManager(getActivity(), 2)); break; } return binding.getRoot(); }
public SmartRecycleView setLayoutManger(LayoutManagerType layoutManagerType, int orientation, int spanCout) { RecyclerView.LayoutManager layoutManager = null; if (layoutManagerType == LayoutManagerType.LINEAR_LAYOUT) { LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext); linearLayoutManager.setOrientation(orientation); layoutManager = linearLayoutManager; } else if (layoutManagerType == LayoutManagerType.GRID_LAYOUT) { GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, spanCout); gridLayoutManager.setOrientation(orientation); layoutManager = gridLayoutManager; } else if (layoutManagerType == LayoutManagerType.STAGGER_LAYOUT) { StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(spanCout, orientation); layoutManager = staggeredGridLayoutManager; } mRecyclerView.setLayoutManager(layoutManager); return this; }
@Override protected void initActivityCreated() { if (!isPrepared || !isVisible || isLoad) { return; } mAdapter = new XRecyclerViewAdapter<>(); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); recyclerView.setLoadingMore(this); recyclerView.setAdapter( mAdapter.setLayoutId(R.layout.item_k567) .onXBind((holder, position, movieModel) -> { holder.setTextView(R.id.k567_item_tv, Html.fromHtml(movieModel.title)); ImageLoaderUtils.display(holder.getImageView(R.id.k567_item_iv), movieModel.url); }) .setOnItemClickListener((view, position, info) -> K567DetailActivity.startIntent(info.title, info.detailUrl, info.url)) ); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.post(this::onRefresh); setLoad(); }
/** * In the case mShowLastDivider = false, * Returns offset for how many views we don't have to draw a divider for, * for LinearLayoutManager it is as simple as not drawing the last child divider, * but for a GridLayoutManager it needs to take the span count for the last items into account * until we use the span count configured for the grid. * * @param parent RecyclerView * @return offset for how many views we don't have to draw a divider or 1 if its a * LinearLayoutManager */ private int getLastDividerOffset(RecyclerView parent) { if (parent.getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); int spanCount = layoutManager.getSpanCount(); int itemCount = parent.getAdapter().getItemCount(); for (int i = itemCount - 1; i >= 0; i--) { if (spanSizeLookup.getSpanIndex(i, spanCount) == 0) { return itemCount - i; } } } return 1; }
/** * 当添加到RecyclerView时获取GridLayoutManager布局管理器,修正header和footer显示整行 * * @param recyclerView the mRecyclerView */ @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager) { final GridLayoutManager gridManager = ((GridLayoutManager) manager); gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return getItemViewType(position) == VIEW_TYPE_HEADER || getItemViewType(position) == VIEW_TYPE_FOOTER ? gridManager.getSpanCount() : 1; } }); } }
private boolean isLastColumn(RecyclerView parent, int pos, int rowCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % rowCount == 0) { // 如果是最后一列,则不需要绘制右侧分割线 return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { if ((pos + 1) % rowCount == 0) { // 如果是最后一列,则不需要绘制右侧分割线 return true; } } else { childCount = childCount - childCount % rowCount; if (pos >= childCount) { // 如果是最后一列,则不需要绘制右侧分割线 return true; } } } return false; }
public void init() { new Thread(new Runnable() { @Override public void run() { try { List<Class> classList = new ClassServiceImpl().getClassListByTeacherId( new TeacherHelper(getContext()).loadUser().get().getId()); final ClassAdapter classAdapter = new ClassAdapter(getContext(), classList); final RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 2); handler.post(new Runnable() { @Override public void run() { recyclerView.setAdapter(classAdapter); recyclerView.setLayoutManager(layoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); progressBar.setVisibility(View.INVISIBLE); } }); } catch (ClassException e) { e.printStackTrace(); } } }).start(); }
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一列,则不需要绘制右边 return true; } } return false; }
public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback) { innerAdapter.onAttachedToRecyclerView(recyclerView); RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup(); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position); } }); gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount()); } }
@Override protected void initData() { mItemsBeen = new ArrayList<>(); mTypeItemAdapter = new LiveTypeItemAdapter(mMainActivity, LiveTypeItemAdapter.TYPE_CATE); mHeaderAndFooterRecyclerViewAdapter = new HeaderAndFooterRecyclerViewAdapter (mTypeItemAdapter); mChijiRecyclerView.setAdapter(mHeaderAndFooterRecyclerViewAdapter); GridLayoutManager manager = new GridLayoutManager(mMainActivity, 2); manager.setSpanSizeLookup(new HeaderSpanSizeLookup((HeaderAndFooterRecyclerViewAdapter) mChijiRecyclerView.getAdapter(), manager.getSpanCount())); mChijiRecyclerView.setLayoutManager(manager); int spacing = ScreenHelper.dp2px(mMainActivity, 15); mChijiRecyclerView.addItemDecoration(new SpaceItemDecoration(2, spacing, spacing, false)); mDetailPresenter.attachView(this); mDetailPresenter.getLiveTypeData(mTypeString, pagerNow, pagerNum); }
@Override public void onAttachedToRecyclerView(final RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager) { final GridLayoutManager gridManager = ((GridLayoutManager) manager); gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { int type = getItemViewType(position); if (mSpanSizeLookup == null) { return (type == EMPTY_VIEW || type == LOADING_VIEW || type == FETCHING_VIEW) ? gridManager.getSpanCount() : 1; } else { return (type == EMPTY_VIEW || type == LOADING_VIEW || type == FETCHING_VIEW) ? gridManager .getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager, position - getFetchMoreViewCount()); } } }); } }
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) { LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一列,则不需要绘制右边 return true; } } return false; }
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View mRootView = inflater.inflate(R.layout.fragment_hotels,container,false); hotels = new ArrayList<>(); mHotelsList = (RecyclerView) mRootView.findViewById(R.id.hotels_recycler); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { mHotelsList.setLayoutManager(new GridLayoutManager(getActivity(), 2)); } else { mHotelsList.setLayoutManager(new GridLayoutManager(getActivity(), 1)); } mAdapter = new HotelDataAdapter(getActivity(),hotels); mAdapter.setActionListner(this); mHotelsList.setAdapter(mAdapter); if (mPresenter != null) mPresenter.loadHotels(); return mRootView; }
private int calculateRecyclerViewFirstPosition() { RecyclerView.LayoutManager manager = mRecyclerView.getLayoutManager(); if (manager instanceof StaggeredGridLayoutManager) { if (mVisiblePositions == null) mVisiblePositions = new int[((StaggeredGridLayoutManager) manager).getSpanCount()]; ((StaggeredGridLayoutManager) manager).findLastCompletelyVisibleItemPositions(mVisiblePositions); int max = -1; for (int pos : mVisiblePositions) { max = Math.max(max, pos); } return max; } else if (manager instanceof GridLayoutManager) { return ((GridLayoutManager) manager).findFirstCompletelyVisibleItemPosition(); } else { return ((LinearLayoutManager) manager).findLastCompletelyVisibleItemPosition(); } }
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Album album = getArguments().getParcelable(EXTRA_ALBUM); mAdapter = new AlbumMediaAdapter(getContext(), mSelectionProvider.provideSelectedItemCollection(), mRecyclerView); mAdapter.registerCheckStateListener(this); mAdapter.registerOnMediaClickListener(this); mRecyclerView.setHasFixedSize(true); int spanCount; SelectionSpec selectionSpec = SelectionSpec.getInstance(); if (selectionSpec.gridExpectedSize > 0) { spanCount = UIUtils.spanCount(getContext(), selectionSpec.gridExpectedSize); } else { spanCount = selectionSpec.spanCount; } mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), spanCount)); int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing); mRecyclerView.addItemDecoration(new MediaGridInset(spanCount, spacing, false)); mRecyclerView.setAdapter(mAdapter); mAlbumMediaCollection.onCreate(getActivity(), this); mAlbumMediaCollection.load(album, selectionSpec.capture); }
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback() { @Override public int getSpanSize(GridLayoutManager gridLayoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) { if (isEmpty()) { return gridLayoutManager.getSpanCount(); } if (oldLookup != null) { return oldLookup.getSpanSize(position); } return 1; } }); }
private void setData() { mRecyclerView.setLayoutManager(new GridLayoutManager(this,1)); //侧滑删除的根布局是SwipeItemLayout这个自定义view mRecyclerView.addOnItemTouchListener(new SwipeItemLayout.OnSwipeItemTouchListener(this)); mRecyclerView.setAdapter(mAdapter); /** * //这几行是之前只侧滑删除没有按钮的实现方式,涉及到ItemTouchHelperAdapter,RvItemTouchHelper两个类 //此处不调用,那两个类也就没用了,但并不删除,因为那种不带按钮的是很简单,不用添加其他东西的 //这种带按钮的要添加一个800行代码的SwipeItemLayout的自定义view类,这也是操作比较简单的一种实现方式 //但只针对recyclerview,能多种适配的比较麻烦,在build.gradle中也引入了,是张旭童博客的,GitHub有源码 //此处标记是怕以后时间长了忘记,关于这种仿iOS qq侧滑删除的今天在网上下了几个demo,存在E盘以s开头的工程 //有差别,但都很牛逼,其实都是自定义view的延伸,我现在水平还到不了那,但以后要往那个方向努力 //此处注释不能删 */ // ItemTouchHelper.Callback callback = new RVItemTouchHelper(mAdapter); // ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); // itemTouchHelper.attachToRecyclerView(mRecyclerView); }
private void initSupplierList() { supplierAdapter = new BRAdapter<SelectedListInfo>(getContext(), R.layout.item_selected_show_list, supplierList) { @Override protected void convert(RvHolder holder, final SelectedListInfo selectedListInfo, int position) { holder.setText(R.id.tv_name, selectedListInfo.name); holder.setOnClickListener(R.id.tv_cancle, new View.OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < supplierList.size(); i++) { if ((supplierList.get(i).name).equals(selectedListInfo.name)) { supplierList.remove(i); i--; } } supplierAdapter.notifyDataSetChanged(); } }); } }; rvSupplier.setAdapter(supplierAdapter); rvSupplier.setLayoutManager(new GridLayoutManager(getContext(), 3)); }
@Override protected void setUpAdapter() { GridLayoutManager glm = new GridLayoutManager(getApplicationContext(), 3); GridAdapter adapter = new GridAdapter(convertDpToPixel(4, this)); adapter.setSpanCount(3); recyclerView.addItemDecoration(adapter.getItemDecorationManager()); glm.setSpanSizeLookup(adapter.getSpanSizeLookup()); recyclerView.setLayoutManager(glm); recyclerView.setAdapter(adapter); List<BaseModel> data = new ArrayList<>(); for (int i = 0; i < 50; i++) { if (i % 10 == 0) { data.add(new Header("Sample header " + i)); } else { data.add(GridItem.generateGridItem(i)); } } adapter.addData(data); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.chat_fragment_group, container, false); listGroup = GroupDB.getInstance(getContext()).getListGroups(); recyclerListGroups = (RecyclerView) layout.findViewById(R.id.recycleListGroup); mSwipeRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.swipeRefreshLayout); mSwipeRefreshLayout.setOnRefreshListener(this); GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 2); recyclerListGroups.setLayoutManager(layoutManager); adapter = new ListMovieAdapter(getContext(), listGroup); recyclerListGroups.setAdapter(adapter); if(listGroup.size() == 0){ //Ket noi server hien thi group mSwipeRefreshLayout.setRefreshing(true); getListGroup(); } return layout; }
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_tvseries_watch_later, container, false); ButterKnife.bind(this, view); realm = Realm.getDefaultInstance(); GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 2); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); rvTvSeriesWatchLater.setLayoutManager(layoutManager); rvTvSeriesWatchLater.setAdapter(new TvSeriesWatchLaterAdapter(realm.where(TvSeries.class) .equalTo("isWatchLater", true).findAllAsync(), true, this)); return view; }
@Override protected void initWidget() { super.initWidget(); mRecyclerField.setLayoutManager(new GridLayoutManager(this, 2)); mAdapter = new FieldAdapter(this); mAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() { @Override public void onItemClick(int position, long itemId) { Field field = mAdapter.getItem(position); if (field == null) return; if (!field.isSelected()) { List<Field> fields = mAdapter.getSelects(); if (fields.size() >= 3) { SimplexToast.show(ModifyFieldActivity.this, "最多选择3个"); return; } } field.setSelected(!field.isSelected()); mAdapter.updateItem(position); } }); mRecyclerField.setAdapter(mAdapter); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); initItemsData(); gridLayoutManager = new GridLayoutManager(this, SPAN_COUNT_ONE); itemAdapter = new ItemAdapter(items, gridLayoutManager); recyclerView = (RecyclerView) findViewById(R.id.rv); recyclerView.setAdapter(itemAdapter); recyclerView.setLayoutManager(gridLayoutManager); }
@Override public void onScrollStateChanged(int state) { super.onScrollStateChanged(state); if (state == RecyclerView.SCROLL_STATE_IDLE && mLoadingListener != null && !isLoadingData && loadingMoreEnabled) { LayoutManager layoutManager = getLayoutManager(); int lastVisibleItemPosition; if (layoutManager instanceof GridLayoutManager) { lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition(); } else if (layoutManager instanceof StaggeredGridLayoutManager) { int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()]; ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into); lastVisibleItemPosition = findMax(into); } else { lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); } if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= layoutManager.getItemCount() - 1 && !isNoMore && mRefreshHeader.getState() < ArrowRefreshHeader.STATE_REFRESHING) { isLoadingData = true; if (mFootView instanceof LoadingMoreFooter) { ((LoadingMoreFooter) mFootView).setState(LoadingMoreFooter.STATE_LOADING); } else { mFootView.setVisibility(View.VISIBLE); } mLoadingListener.onLoadMore(); } } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View views = inflater.inflate(R.layout.fragment_base_view, container, false); unbinder = ButterKnife.bind(this,views); progressLayout.showLoading(); swipeRefreshLayout.setOnRefreshListener(this); recyclerView.setHasFixedSize(true); //originally set to fixed size true recyclerView.setNestedScrollingEnabled(false);//set to false if somethings fail to work properly mLayoutManager = new GridLayoutManager(getContext(), getResources().getInteger(R.integer.card_col_size_home)); recyclerView.setLayoutManager(mLayoutManager); if(savedInstanceState != null) model_type = savedInstanceState.getString(MODEL_TYPE); return views; }
private void setupAlbum(Path path) { mPath = path; mRootObject = getDataManager().getMediaSet(path); mRootObject.addContentListener(() -> mAdapter.notifyDataSetChanged()); mAdapter = new AlbumSetAdapter(mRootObject, this,this); mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2)); mRecyclerView.setAdapter(mAdapter); mRootObject.reload(); }
public void initUI() { // searchText = (EditText) findViewById(R.id.search_bar_default); frameContainer = (LinearLayout) findViewById(R.id.frame_default); flSearch = (FrameLayout) findViewById(R.id.frame_default_search); rvDefault = (RecyclerView) findViewById(R.id.list_view_default); GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false); rvDefault.setLayoutManager(gridLayoutManager); layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false); }
protected void initRecyclerView() { mSectionedRecyclerViewAdapter = new SectionedRecyclerViewAdapter(); GridLayoutManager mGridLayoutManager = new GridLayoutManager(getActivity(), 3); mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch (mSectionedRecyclerViewAdapter.getSectionItemViewType(position)) { case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER: return 3; default: return 1; } } }); mRecyclerView.setHasFixedSize(true); mRecyclerView.setNestedScrollingEnabled(true); mRecyclerView.setLayoutManager(mGridLayoutManager); mRecyclerView.setAdapter(mSectionedRecyclerViewAdapter); setRecycleNoScroll(); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_home_lines, container, false); // Set the adapter Context context = view.getContext(); recyclerView = (RecyclerView) view.findViewById(R.id.list); if (mColumnCount <= 1) { recyclerView.setLayoutManager(new LinearLayoutManager(context)); } else { recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); } recyclerView.setVisibility(View.GONE); progressBar = (ProgressBar) view.findViewById(R.id.loading_indicator); progressBar.setVisibility(View.VISIBLE); updateInformationView = (TextView) view.findViewById(R.id.update_information); // fix scroll fling. less than ideal, but apparently there's still no other solution recyclerView.setNestedScrollingEnabled(false); IntentFilter filter = new IntentFilter(); filter.addAction(MainActivity.ACTION_MAIN_SERVICE_BOUND); filter.addAction(MainService.ACTION_UPDATE_TOPOLOGY_FINISHED); filter.addAction(LineStatusCache.ACTION_LINE_STATUS_UPDATE_STARTED); filter.addAction(LineStatusCache.ACTION_LINE_STATUS_UPDATE_SUCCESS); filter.addAction(LineStatusCache.ACTION_LINE_STATUS_UPDATE_FAILED); LocalBroadcastManager bm = LocalBroadcastManager.getInstance(context); bm.registerReceiver(mBroadcastReceiver, filter); redraw(context); return view; }
private void initRecycleView() { GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), GRID_COUNT); gridLayoutManager.setSmoothScrollbarEnabled(true); mRecycleView.setLayoutManager(gridLayoutManager); mRecycleView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelOffset(R.dimen.boxing_media_margin), GRID_COUNT)); mMediaAdapter.setOnCameraClickListener(new OnCameraClickListener()); mMediaAdapter.setOnCheckedListener(new OnMediaCheckedListener()); mMediaAdapter.setOnMediaClickListener(new OnMediaClickListener()); mRecycleView.setAdapter(mMediaAdapter); mRecycleView.addOnScrollListener(new ScrollListener()); }
public EndlessRecyclerViewScrollListener(int currentPage, RecyclerView.LayoutManager layoutManager) { this.mCurrentPage = currentPage; this.mLayoutManager = layoutManager; if (layoutManager instanceof GridLayoutManager) { mVisibleThreshold *= ((GridLayoutManager) layoutManager).getSpanCount(); } else if (layoutManager instanceof LinearLayoutManager) { mVisibleThreshold = ENDLESS_PAGINATION_THRESHOLD * 2; } }
public MonthRecyclerView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); mAdapter = new MonthAdapter(context); setLayoutManager(new GridLayoutManager(context, 3)); setAdapter(mAdapter); mAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() { @Override public void onItemClick(int position, long itemId) { if (mListener != null) { Month month = mAdapter.getItem(position); mListener.onMonthSelected(month.getYear(), month.getMonth()); } } }); }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (adapter == null) { adapter = new AssistantAdapter(getActivity(), itemPerRow); adapter.addHeader(new View(getActivity())); adapter.addFooter(new View(getActivity())); } gridLayoutManager = new GridLayoutManager(getActivity(), itemPerRow); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return adapter.getSpanSize(position); } }); ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(getContext(), R.dimen.grid_offset); recyclerView.addItemDecoration(itemDecoration); recyclerView.setLayoutManager(gridLayoutManager); recyclerView.setAdapter(adapter); if (((MainActivity) getActivity()).positionMap.containsKey(TAG)) { offset = ((MainActivity) getActivity()).positionMap.get(TAG); } }
@Override protected void onPostExecute(String s) { super.onPostExecute(s); if (s != null && !s.equals("")) { DoubanMovies doubanMovies = new Gson().fromJson(s, DoubanMovies.class); final List<MovieBean> dataset = Arrays.asList(doubanMovies.getSubjects()); GridLayoutManager gridLayoutMgr = new GridLayoutManager(CelebrityActivity.this, 4); recyclerView.setLayoutManager(gridLayoutMgr); MovieSubjectAdapter adapter = new MovieSubjectAdapter(dataset) { @Override public void onBindViewHolder(MovieSubjectAdapter.ViewHolder holder, int position) { super.onBindViewHolder(holder, position); MovieBean movie = dataset.get(position); holder.title.setText(movie.getTitle() + "\n" + join(movie.getGenres(), "/")); } }; recyclerView.setAdapter(adapter); setSubjectMoreBtn(doubanMovies.getTotal()); } else { Toast.makeText( CelebrityActivity.this, getString(R.string.douban_error), Toast.LENGTH_LONG ).show(); } subjectPB.setVisibility(View.GONE); subjectMoreBtn.setVisibility(View.VISIBLE); }