Skip to content

Commit

Permalink
demo 完善示例代码
Browse files Browse the repository at this point in the history
  • Loading branch information
youlookwhat committed Jan 3, 2020
1 parent b140501 commit 7f462e3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.view.View;
import android.view.ViewGroup;

import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -52,15 +51,15 @@ private void initAdapter() {
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.VERTICAL);
binding.recyclerView.setLayoutManager(layoutManager);
binding.recyclerView.addItemDecoration(new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL).setDrawable(R.drawable.shape_line));
binding.recyclerView.addItemDecoration(new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL,4).setDrawable(R.drawable.shape_line));
binding.recyclerView.setAdapter(mAdapter);
binding.recyclerView.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {
@Override
public void onLoadMore() {
binding.recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if (page == 1) {
if (page == 2) {
binding.recyclerView.loadMoreEnd();
return;
}
Expand All @@ -84,6 +83,12 @@ public void onClick(View v, int position) {
binding.recyclerView.addHeaderView(R.layout.layout_header_view);
binding.recyclerView.addHeaderView(headerBinding.getRoot());

binding.recyclerView.setOnRefreshListener(new ByRecyclerView.OnRefreshListener() {
@Override
public void onRefresh() {
binding.recyclerView.setRefreshing(false);
}
});
headerBinding.tvText.setText("头布局1\n(点我添加Header2)");
footerBinding.tvText.setText("尾布局1\n(点我添加Footer2)");
header2Binding.tvText.setText("头布局2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ private void initAdapter() {
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 6, RecyclerView.VERTICAL, false);
binding.recyclerView.setLayoutManager(gridLayoutManager);

SpacesItemDecoration itemDecoration = new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL);
SpacesItemDecoration itemDecoration = new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL, 1);
itemDecoration.setDrawable(R.drawable.shape_line);
binding.recyclerView.addItemDecoration(itemDecoration);
binding.recyclerView.setAdapter(mAdapter);
binding.recyclerView.addHeaderView(R.layout.layout_header_view);
binding.recyclerView.setOnRefreshListener(new ByRecyclerView.OnRefreshListener() {
@Override
public void onRefresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ private void initAdapter() {
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.VERTICAL);
binding.recyclerView.setLayoutManager(layoutManager);
SpacesItemDecoration itemDecoration = new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL);
itemDecoration.setDrawable(R.drawable.shape_line);
binding.recyclerView.addItemDecoration(itemDecoration);
binding.recyclerView.setRefreshEnabled(true);
binding.recyclerView.addItemDecoration(new SpacesItemDecoration(this).setHeaderNoShowDivider(1).setDrawable(R.drawable.shape_line));
binding.recyclerView.setAdapter(mAdapter);
binding.recyclerView.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MultiAdapter(List<DataItemBean> data) {

@Override
public int getItemViewType(int position) {
if (position < getData().size()) {
if (0 <= position && position < getData().size()) {
DataItemBean itemData = getItemData(position);
if ("title".equals(itemData.getType())) {
return StickyView.TYPE_STICKY_VIEW;
Expand All @@ -52,10 +52,12 @@ public void onAttachedToRecyclerView(@NonNull final RecyclerView recyclerView) {
gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int type = getItemViewType(position);
if (byRecyclerView.isLoadMoreView(position)) {
if (byRecyclerView.isLoadMoreView(position)
|| byRecyclerView.isRefreshHeader(position)
|| byRecyclerView.isHeaderView(position)) {
return gridManager.getSpanCount();
}
int type = getItemViewType(position - byRecyclerView.getCustomTopItemViewCount());
switch (type) {
case StickyView.TYPE_STICKY_VIEW:
// title栏显示一列
Expand Down

0 comments on commit 7f462e3

Please sign in to comment.