com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter Java Examples
The following examples show how to use
com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchContentFragment.java From Yuan-SxMusic with Apache License 2.0 | 6 votes |
@Override public void setSongsList(final ArrayList<SearchSong.DataBean.SongBean.ListBean> songListBeans) { mSongList.addAll(songListBeans); mAdapter = new SearchContentAdapter(mSongList, mSeek, getActivity(), Constant.TYPE_SONG); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mAdapter); mRecycler.setLayoutManager(manager); mRecycler.setAdapter(mLRecyclerViewAdapter); //点击播放 SearchContentAdapter.setItemClick(position -> { SearchSong.DataBean.SongBean.ListBean dataBean = mSongList.get(position); Song song = new Song(); song.setSongId(dataBean.getSongmid()); song.setSinger(getSinger(dataBean)); song.setSongName(dataBean.getSongname()); song.setImgUrl(Api.ALBUM_PIC+dataBean.getAlbummid()+Api.JPG); song.setDuration(dataBean.getInterval()); song.setOnline(true); song.setMediaId(dataBean.getStrMediaMid()); song.setDownload(DownloadUtil.isExistOfDownloadSong(dataBean.getSongmid())); //网络获取歌曲地址 mPresenter.getSongUrl(song); }); }
Example #2
Source File: GridItemDecoration.java From LRecyclerView with Apache License 2.0 | 6 votes |
public void drawHorizontal(Canvas c, RecyclerView parent) { int childCount = parent.getChildCount(); LRecyclerView recyclerView = (LRecyclerView) parent; LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); for (int i = 0; i < childCount; i++) { if ((recyclerView.isOnTop() && (adapter.isHeader(i) || adapter.isRefreshHeader(i))) || adapter.isFooter(i)) { c.drawRect(0, 0, 0, 0, mPaint); } else { final View child = parent.getChildAt(i); final int top = child.getBottom(); final int bottom = top + verticalSpace; int left = child.getLeft(); int right = child.getRight(); c.drawRect(left, top, right, bottom, mPaint); } } }
Example #3
Source File: GridItemDecoration.java From LRecyclerView with Apache License 2.0 | 6 votes |
public void drawVertical(Canvas c, RecyclerView parent) { final int childCount = parent.getChildCount(); LRecyclerView recyclerView = (LRecyclerView) parent; LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); for (int i = 0; i < childCount; i++) { if ((recyclerView.isOnTop() && (adapter.isHeader(i) || adapter.isRefreshHeader(i))) || adapter.isFooter(i)) { c.drawRect(0, 0, 0, 0, mPaint); } else { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getTop(); final int bottom = child.getBottom() + verticalSpace; final int left = child.getRight() + params.rightMargin; final int right = left + horizontalSpace; c.drawRect(left, top, right, bottom, mPaint); } } }
Example #4
Source File: SpacesItemDecoration.java From LRecyclerView with Apache License 2.0 | 6 votes |
public void drawHorizontal(Canvas c, RecyclerView parent,LRecyclerViewAdapter adapter) { int count = parent.getChildCount(); for (int i = 0; i < count; i++) { final View child = parent.getChildAt(i); final int top = child.getBottom(); final int bottom = top + verticalSpacing; int left = child.getLeft() ; int right = child.getRight(); int position = parent.getChildAdapterPosition(child); c.save(); if (adapter.isRefreshHeader(position) || adapter. isHeader(position) || adapter.isFooter(position)) { c.drawRect(0, 0, 0, 0, mPaint); }else { c.drawRect(left, top, right, bottom, mPaint); } c.restore(); } }
Example #5
Source File: SpacesItemDecoration.java From LRecyclerView with Apache License 2.0 | 6 votes |
public void drawVertical(Canvas c, RecyclerView parent,LRecyclerViewAdapter adapter) { int count = parent.getChildCount(); for (int i = 0; i < count; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getTop(); //final int bottom = child.getBottom() + params.bottomMargin; final int bottom = child.getBottom() + verticalSpacing; //这里使用verticalSpacing 代替 params.bottomMargin final int left = child.getRight() + params.rightMargin; final int right = left + itemSplitMarginEven*2; int position = parent.getChildAdapterPosition(child); c.save(); if (adapter.isRefreshHeader(position) || adapter. isHeader(position) || adapter.isFooter(position)) { c.drawRect(0, 0, 0, 0, mPaint); }else { c.drawRect(left, top, right, bottom, mPaint); } c.restore(); } }
Example #6
Source File: SearchContentFragment.java From Yuan-SxMusic with Apache License 2.0 | 5 votes |
@Override public void searchAlbumSuccess(final List<Album.DataBean.AlbumBean.ListBean> albumList) { mAlbumList = new ArrayList<>(); mAlbumList.addAll(albumList); mAdapter = new SearchContentAdapter(mAlbumList, mSeek, getActivity(), Constant.TYPE_ALBUM); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mAdapter); mRecycler.setLayoutManager(manager); mRecycler.setAdapter(mLRecyclerViewAdapter); SearchContentAdapter.setAlbumClick(position -> toAlbumContentFragment(mAlbumList.get(position))); }
Example #7
Source File: DoubleHeaderFragment.java From LRecyclerView with Apache License 2.0 | 5 votes |
@Override protected void setAdapterAndDecor(RecyclerView list) { final DoubleHeaderTestAdapter adapter = new DoubleHeaderTestAdapter(this.getActivity()); decor = new DoubleHeaderDecoration(adapter); setHasOptionsMenu(true); mLRecyclerViewAdapter = new LRecyclerViewAdapter(adapter); list.setAdapter(mLRecyclerViewAdapter); list.addItemDecoration(decor, 1); list.addOnItemTouchListener(this); }
Example #8
Source File: StickyHeaderFragment.java From LRecyclerView with Apache License 2.0 | 5 votes |
@Override protected void setAdapterAndDecor(RecyclerView list) { final StickyTestAdapter adapter = new StickyTestAdapter(this.getActivity()); decor = new StickyHeaderDecoration(adapter); setHasOptionsMenu(true); mLRecyclerViewAdapter = new LRecyclerViewAdapter(adapter); list.setAdapter(mLRecyclerViewAdapter); list.addItemDecoration(decor, 1); list.addOnItemTouchListener(this); }
Example #9
Source File: InlineStickyHeaderFragment.java From LRecyclerView with Apache License 2.0 | 5 votes |
@Override protected void setAdapterAndDecor(RecyclerView list) { final InlineStickyTestAdapter adapter = new InlineStickyTestAdapter(this.getActivity()); decor = new StickyHeaderDecoration(adapter, true); setHasOptionsMenu(true); mLRecyclerViewAdapter = new LRecyclerViewAdapter(adapter); list.setAdapter(mLRecyclerViewAdapter); list.addItemDecoration(decor, 1); }
Example #10
Source File: RecyclerViewUtils.java From LRecyclerView with Apache License 2.0 | 5 votes |
/** * 请使用本方法替代RecyclerView.ViewHolder的getLayoutPosition()方法 * * @param recyclerView * @param holder * @return */ public static int getLayoutPosition(RecyclerView recyclerView, RecyclerView.ViewHolder holder) { RecyclerView.Adapter outerAdapter = recyclerView.getAdapter(); if (outerAdapter != null && outerAdapter instanceof LRecyclerViewAdapter) { int headerViewCounter = ((LRecyclerViewAdapter) outerAdapter).getHeaderViewsCount(); if (headerViewCounter > 0) { return holder.getLayoutPosition() - (headerViewCounter + 1); } } return holder.getLayoutPosition(); }
Example #11
Source File: SpacesItemDecoration.java From LRecyclerView with Apache License 2.0 | 5 votes |
private static int getItemBottomSpacing(SpanLookup spanLookup, int verticalSpacing, int itemPosition, int childCount, LRecyclerViewAdapter adapter) { if(adapter.isHeader(itemPosition) || adapter.isRefreshHeader(itemPosition) || adapter.isFooter(itemPosition)) { return 0; } else { if (itemIsOnTheBottomRow(spanLookup, itemPosition, childCount)) { return 0; } else { return (int) (.5f * verticalSpacing); } } }
Example #12
Source File: SpacesItemDecoration.java From LRecyclerView with Apache License 2.0 | 5 votes |
private static int getItemTopSpacing(SpanLookup spanLookup, int verticalSpacing, int itemPosition, int spanCount, int childCount, LRecyclerViewAdapter adapter) { if(adapter.isHeader(itemPosition) || adapter.isRefreshHeader(itemPosition) || adapter.isFooter(itemPosition)) { return 0; } else { if (itemIsOnTheTopRow(spanLookup, itemPosition, spanCount, childCount)) { return 0; } else { return (int) (.5f * verticalSpacing); } } }
Example #13
Source File: GridItemDecoration.java From LRecyclerView with Apache License 2.0 | 5 votes |
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount) { LayoutManager layoutManager = parent.getLayoutManager(); LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); if (layoutManager instanceof GridLayoutManager) { if ((pos - adapter.getHeaderViews().size()) % spanCount == 0) // 如果是最后一列,则不需要绘制右边 return true; } return false; }
Example #14
Source File: GridItemDecoration.java From LRecyclerView with Apache License 2.0 | 5 votes |
/** * @param parent RecyclerView * @param pos 当前item的位置 * @param spanCount 每行显示的item个数 * @param childCount child个数 */ private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) { LayoutManager layoutManager = parent.getLayoutManager(); LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); if (layoutManager instanceof GridLayoutManager) { int leftCount = childCount - childCount % spanCount;//3 //leftCount:若childCount能被span整除为childCount否则为去掉最后一行的item总数 if ((pos - adapter.getHeaderViews().size() + 1) > leftCount) { return true; } } return false; }
Example #15
Source File: SpacesItemDecoration.java From LRecyclerView with Apache License 2.0 | 4 votes |
private void applyItemVerticalOffsets(Rect outRect, int itemPosition, int childCount, int spanCount, SpanLookup spanLookup,LRecyclerViewAdapter adapter) { outRect.top = getItemTopSpacing(spanLookup, verticalSpacing, itemPosition, spanCount, childCount,adapter); outRect.bottom = getItemBottomSpacing(spanLookup, verticalSpacing, itemPosition, childCount,adapter); }
Example #16
Source File: GridItemDecoration.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) { super.getItemOffsets(outRect, view, parent, state); int itemPosition = parent.getChildAdapterPosition(view); int spanCount = getSpanCount(parent); int childCount = parent.getAdapter().getItemCount(); LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); if (adapter.isFooter(itemPosition) || adapter.isHeader(itemPosition) || adapter.isRefreshHeader(itemPosition)) { //header,footer不进行绘制 outRect.set(0, 0, 0, 0); } else { if (!(parent.getLayoutManager() instanceof GridLayoutManager)) { //LinearLayoutManager if (itemPosition == (childCount - 2 - adapter.getHeaderViews().size())) outRect.set(0, 0, 0, 0); else outRect.set(0, 0, 0, verticalSpace); } else { //GridLayoutManager if (isLastRaw(parent, itemPosition, spanCount, childCount - 2 - adapter.getHeaderViews().size())) { //最后一行 if (isLastColumn(parent, itemPosition, spanCount)) { // 最后一行最后一列 outRect.set(0, 0, 0, verticalSpace); } else { // 最后一行不是最后一列 outRect.set(0, 0, horizontalSpace, verticalSpace); } } else { //最后一列 if (isLastColumn(parent, itemPosition, spanCount)) { // 最后一列最后一行 outRect.set(0, 0, 0, verticalSpace); } else { // 最后一列非最后一行 outRect.set(0, 0, horizontalSpace, verticalSpace); } } } } }
Example #17
Source File: GankAndroidFragment.java From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 | 4 votes |
@TargetApi(21) private void initView() { mRecyclerView.setLayoutManager(new LinearLayoutManager(activity)); mDataAdapter = new DataAdapter<>(activity); mDataAdapter.setDataList(mData); lRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(lRecyclerViewAdapter); mRecyclerView.setRefreshProgressStyle(ProgressStyle.TriangleSkewSpin); mRecyclerView.setOnRefreshListener(this); mRecyclerView.setOnLoadMoreListener(this); mRecyclerView.forceToRefresh(); lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(View view, int position) { FabCloseEvent fabCloseEvent = new FabCloseEvent(); fabCloseEvent.status = 1; EventBus.getDefault().post(fabCloseEvent); Intent i = new Intent(activity, DetailActivity.class); MyFavorite favorite = new MyFavorite(); favorite.setTitle("Android"); favorite.setContentDiscription(mData.get(position).desc); favorite.setUrl(mData.get(position).url); favorite.setFavoriteId(mData.get(position)._id); favorite.setCollectTime(""); try { favorite.setImgUrl(mData.get(position).images[0]); } catch (Exception e) { Snackbar.make(mRecyclerView, "未获取到图片url", Snackbar.LENGTH_SHORT).show(); favorite.setImgUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494938304958&di=854d61b39d45b938505f573f6be7322f&imgtype=0&src=http%3A%2F%2Ff5.topit.me%2F5%2Fff%2F7e%2F11774047714a97eff5o.jpg"); }finally { Bundle bundle = new Bundle(); bundle.putSerializable(Config.MYFAVOTITE,favorite); i.putExtras(bundle); View sharedView = view.findViewById(R.id.iv_item_gank); String transitionName = getString(R.string.transitionName); ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(activity, sharedView, transitionName); startActivity(i, transitionActivityOptions.toBundle()); } } }); // // PackageManager packageManager = activity.getPackageManager(); // try { // Drawable applicationIcon = packageManager.getApplicationIcon("com.zchz.app"); // Toast toast = new Toast(activity); // ImageView imageView = new ImageView(activity); // imageView.setImageDrawable(applicationIcon); // toast.setView(imageView); // toast.setDuration(Toast.LENGTH_LONG); // toast.show(); // } catch (PackageManager.NameNotFoundException e) { // e.printStackTrace(); // } }
Example #18
Source File: BilibiliActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); mRecyclerView.setLayoutManager(new GridLayoutManager(this,2)); mVisitables = getData(); mMainAdapter = new MainAdapter(new ListTypeFactory(), mVisitables); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mMainAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() { @Override public int getSpanSize(GridLayoutManager gridLayoutManager, int position) { Object item = mVisitables.get(position); return (item instanceof HotList || item instanceof ProductList || item instanceof Category) ? gridLayoutManager.getSpanCount() : 1; } }); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { mRecyclerView.refreshComplete(10); } },1000); } }); mRecyclerView.refresh(); mRecyclerView.setLoadMoreEnabled(false); //是否允许嵌套滑动 mRecyclerView.setNestedScrollingEnabled(false); }
Example #19
Source File: ExpandableActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); mDataAdapter = new ExpandableItemAdapter(this); mDataAdapter.setDataList(generateData()); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); DividerDecoration divider = new DividerDecoration.Builder(this) .setHeight(R.dimen.default_divider_height) .setPadding(R.dimen.default_divider_padding) .setColorResource(R.color.split) .build(); //mRecyclerView.setHasFixedSize(true); mRecyclerView.addItemDecoration(divider); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); //add a HeaderView View header = LayoutInflater.from(this).inflate(R.layout.sample_header,(ViewGroup)findViewById(android.R.id.content), false); mLRecyclerViewAdapter.addHeaderView(header); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); //禁用下拉刷新功能 mRecyclerView.setPullRefreshEnabled(false); //禁用自动加载更多功能 //mRecyclerView.setLoadMoreEnabled(false); //add a FooterView //mLRecyclerViewAdapter.addFooterView(sampleFooter); }
Example #20
Source File: AlipayHomeActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_alipay_home); StatusBarUtil.setColor(AlipayHomeActivity.this, ContextCompat.getColor(this,R.color.blue_black), 0); //AppBarLayout abl_bar = (AppBarLayout) findViewById(R.id.abl_bar); abl_bar.addOnOffsetChangedListener(this); //顶部搜索布局 include_toolbar_search = findViewById(R.id.include_toolbar_search); //扫一扫 付一付 聊一聊 咻一咻 的小图标布局 include_toolbar_small = findViewById(R.id.include_toolbar_small); //顶部搜索布局遮罩 v_toolbar_search_mask = findViewById(R.id.v_toolbar_search_mask); //扫一扫 付一付 聊一聊 咻一咻 的大图标布局遮罩 v_title_big_mask = findViewById(R.id.v_title_big_mask); //扫一扫 付一付 聊一聊 咻一咻 的大图标布局遮罩 v_toolbar_small_mask = findViewById(R.id.v_toolbar_small_mask); //背景颜色 mMaskColor = getResources().getColor(R.color.blue_dark); mRecyclerView = findViewById(R.id.list); //init data ArrayList<ItemModel> dataList = new ArrayList<>(); for (int i = 0; i < 10; i++) { ItemModel itemModel = new ItemModel(); itemModel.title = "item" + i; dataList.add(itemModel); } mDataAdapter = new DataAdapter(this); mDataAdapter.setDataList(dataList); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); //禁用自动加载更多功能 mRecyclerView.setLoadMoreEnabled(false); SampleFooter sampleFooter = new SampleFooter(this); //add a FooterView mLRecyclerViewAdapter.addFooterView(sampleFooter); mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { mRecyclerView.refreshComplete(10); } }, 800); } }); }
Example #21
Source File: ExpandableRecyclerViewOneActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); mDataAdapter = new CommentExpandAdapter(this,mRecyclerView); mDataAdapter.setMode(ExpandableRecyclerAdapter.MODE_ACCORDION); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); mRecyclerView.setArrowImageView(R.drawable.ic_pulltorefresh_arrow); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mCurrentCounter = 0; isRefresh = true; requestData(); } }); mRecyclerView.refresh(); //不要在调用下面代码 /*mLRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(View view, int position) { //ItemModel item = mDataAdapter.getDataList().get(position); //AppToast.showShortText(ExpandableRecyclerViewOneActivity.this, item.title); } @Override public void onItemLongClick(View view, int position) { //ItemModel item = mDataAdapter.getDataList().get(position); //AppToast.showShortText(ExpandableRecyclerViewOneActivity.this, "onItemLongClick - " + item.title); } });*/ }
Example #22
Source File: ListDragMenuActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); //setLayoutManager must before setAdapter mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); //init data ArrayList<ItemModel> dataList = new ArrayList<>(); for (int i = 0; i < 16; i++) { ItemModel itemModel = new ItemModel(); itemModel.title = "item" + i; dataList.add(itemModel); } mItemTouchHelper = new ItemTouchHelper(mCallback); mItemTouchHelper.attachToRecyclerView(mRecyclerView); mDataAdapter = new DataAdapter(this); mDataAdapter.setDataList(dataList); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); DividerDecoration divider = new DividerDecoration.Builder(this) .setHeight(R.dimen.default_divider_height) .setPadding(R.dimen.default_divider_padding) .setColorResource(R.color.split) .build(); mRecyclerView.addItemDecoration(divider); mRecyclerView.setHasFixedSize(true); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); //add a FooterView mLRecyclerViewAdapter.addFooterView(new SampleFooter(this)); //禁用下拉刷新功能 mRecyclerView.setPullRefreshEnabled(false); //禁用自动加载更多功能 mRecyclerView.setLoadMoreEnabled(false); }
Example #23
Source File: Nest2RecyclerViewActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); mRecyclerView.setNestedScrollingEnabled(false); mShopAdapter = new ShopAdapterBase(this,mGoodsList); //setLayoutManager must before setAdapter GridLayoutManager layoutManager = new GridLayoutManager(this, 2); mRecyclerView.setLayoutManager(layoutManager); initData(); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mShopAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); mShopAdapter.addAll(mItemModels); DividerDecoration divider = new DividerDecoration.Builder(this) .setHeight(R.dimen.default_divider_height) .setPadding(R.dimen.default_divider_padding) .setColorResource(R.color.split) .build(); mRecyclerView.setHasFixedSize(true); mRecyclerView.addItemDecoration(divider); mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() { @Override public int getSpanSize(GridLayoutManager gridLayoutManager, int position) { MultipleItem item = mShopAdapter.getDataList().get(position); if (item.getItemType() == MultipleItem.LIST) { return gridLayoutManager.getSpanCount(); } else { return 1; } } }); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { mRecyclerView.refreshComplete(10); } },1000); } }); mRecyclerView.refresh(); //是否允许嵌套滑动 mRecyclerView.setNestedScrollingEnabled(false); }
Example #24
Source File: EndlessGridLayoutActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); //setLayoutManager must before setAdapter GridLayoutManager manager = new GridLayoutManager(this, 2); mRecyclerView.setLayoutManager(manager); mDataAdapter = new DataAdapter(this); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); //设置头部加载颜色 mRecyclerView.setHeaderViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white); //设置底部加载颜色 mRecyclerView.setFooterViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white); //设置底部加载文字提示 mRecyclerView.setFooterViewHint("拼命加载中","已经全部为你呈现了","网络不给力啊,点击再试一次吧"); int spacing = getResources().getDimensionPixelSize(R.dimen.dp_4); mRecyclerView.addItemDecoration(SpacesItemDecoration.newInstance(spacing, spacing, manager.getSpanCount(), Color.GRAY)); //根据需要选择使用GridItemDecoration还是SpacesItemDecoration GridItemDecoration divider = new GridItemDecoration.Builder(this) .setHorizontal(R.dimen.default_divider_padding) .setVertical(R.dimen.default_divider_padding) .setColorResource(R.color.split) .build(); //mRecyclerView.addItemDecoration(divider); mRecyclerView.setHasFixedSize(true); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); //设置span,自己可以体验效果 /*mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() { @Override public int getSpanSize(GridLayoutManager gridLayoutManager, int position) { if (position % 4 == 0) { return gridLayoutManager.getSpanCount(); } else { return 1; } } });*/ mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mCurrentCounter = 0; mDataAdapter.clear(); requestData(); } }); mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore() { if (mCurrentCounter < TOTAL_COUNTER) { // loading more requestData(); } else { //the end mRecyclerView.setNoMore(true); } } }); mRecyclerView.refresh(); }
Example #25
Source File: CollapsingToolbarLayoutActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_collapsing_toolbar_layout); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); //init data ArrayList<ItemModel> dataList = new ArrayList<>(); for (int i = 0; i < 10; i++) { ItemModel item = new ItemModel(); item.id = i; item.title = "item" + i; dataList.add(item); } mCurrentCounter = dataList.size(); mDataAdapter = new DataAdapter(this); mDataAdapter.addAll(dataList); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); DividerDecoration divider = new DividerDecoration.Builder(this) .setHeight(R.dimen.default_divider_height) .setPadding(R.dimen.default_divider_padding) .setColorResource(R.color.split) .build(); mRecyclerView.setHasFixedSize(true); mRecyclerView.addItemDecoration(divider); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mCurrentCounter = 0; mDataAdapter.clear(); requestData(); } }); mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore() { if (mCurrentCounter < TOTAL_COUNTER) { // loading more requestData(); } else { //the end mRecyclerView.setNoMore(true); } } }); }
Example #26
Source File: EndlessStaggeredGridLayoutActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_ll_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (LRecyclerView) findViewById(R.id.list); mDataAdapter = new DataAdapter(this); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); //setLayoutManager StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( 2, StaggeredGridLayoutManager.VERTICAL); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); //防止item位置互换 layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); mRecyclerView.setLayoutManager(layoutManager); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this)); mRecyclerView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mCurrentCounter = 0; mDataAdapter.clear(); requestData(); } }); mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore() { if (mCurrentCounter < TOTAL_COUNTER) { // loading more requestData(); } else { //the end mRecyclerView.setNoMore(true); } } }); mRecyclerView.refresh(); }