android网页省略分页器,Android轻量级网页风格分页器

博客同步自:个人博客主页

轻量级仿网页风格分页器,和RecycleView封装一起配合使用,也可单独使用,喜欢就star、fork下吧~谢谢

目录

功能介绍

效果图

如何引入

简单使用

依赖

github地址

功能介绍

支持延迟加载分页

支持单独分页器组件使用;同时封装了RecycleView,可以配合使用

支持加载状态改变提示

支持自定义数字指示器数量、选中和未选中等样式

效果图

586a2c378a1816ec325d20e46514fea3.png

5925a5f1a3b1b1d873146a06419f781b.png

Screenshots

如何引入

Gradle引入

step 1

Add the JitPack repository to your build file

allprojects {

repositories {

...

maven { url 'https://jitpack.io' }

}

}

Step 2

Add the dependency

dependencies {

implementation 'com.github.itlwy:PaginationExample:0.0.20'

}

简单使用

组合RecycleView使用

此时使用的是PaginationRecycleView类

activity_main.xml ...

android:id="@+id/pagination_rcv"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginBottom="8dp"

app:number_tip_count="5"

app:rect_size="30dp"

app:selected_color="@color/indicator_rect_selected"

app:text_size="14sp"

app:unselected_color="@color/indicator_rect_unselected"

/>

...

MainActivity.java ...

@Override

protected void onCreate(Bundle savedInstanceState) {

mPaginationRcv = findViewById(R.id.pagination_rcv);

mAdapter = new CustomAdapter(this, 99);

mPaginationRcv.setAdapter(mAdapter);

// mPaginationRcv.setPerPageCountChoices(perPageCountChoices);

GridLayoutManager layoutManager = new GridLayoutManager(this, 3);

mPaginationRcv.setLayoutManager(layoutManager);

mPaginationRcv.setListener(new PaginationRecycleView.Listener() {

@Override

public void loadMore(int currentPagePosition, int nextPagePosition, int perPageCount, int dataTotalCount) {

// nextPagePosition为将要加载的页码,即需要加载数据的页

// perPageCount 每页展示的数量

//TODO : 此处进行异步数据加载

//TODO : 完成加载后通知分页控件(注意此处应该是在主线程运行),如下

mAdapter.setDatas(nextPagePosition, data);

mPaginationRcv.setState(PaginationRecycleView.SUCCESS);

}

@Override

public void onPerPageCountChanged(int perPageCount) {

// "x条/每页"Spinner选中值改变时触发

}

});

mAdapter.setOnItemClickListener(this);

}

@Override

public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {

JSONObject item = mAdapter.getCurrentPageItem(position); // 此处position返回的是recycleview的位置,所以取当前页显示列表的项

Toast.makeText(this, item.optString("name"), Toast.LENGTH_LONG).show();

}

...

CustomAdapter class CustomAdapter extends PaginationRecycleView.Adapter {

private Context mContext;

public CustomAdapter(Context context, int dataTotalCount) {

super(dataTotalCount);

mContext = context;

}

@Override

public void bindViewHolder(ViewHolder viewholder, JSONObject data) {

viewholder.setText(R.id.text, data.optString("name"));

}

@Override

public ViewHolder createViewHolder(@NonNull ViewGroup parent, int viewTypea) {

return ViewHolder.createViewHolder(mContext, parent, R.layout.item_list);

}

}

布局文件中的属性说明: app:number_tip_count="5" // 数字指示器显示的数量,默认是5

app:rect_size="30dp"// 圆角矩形的大小(正方形)

app:selected_color="@color/indicator_rect_selected" // 选中的颜色(包含框和字体)

app:text_size="14sp" // 字体大小

app:unselected_color="@color/indicator_rect_unselected" 未选中的颜色(包含框和字体)

单独使用

​ 此时使用的是PaginationIndicator类,布局如下:

...

android:id="@+id/indicator"

android:layout_width="match_parent"

app:number_tip_count="5"

app:rect_size="30dp"

app:selected_color="@color/indicator_rect_selected"

app:text_size="14sp"

app:unselected_color="@color/indicator_rect_unselected"

android:layout_height="wrap_content">

...

​ 说明如上述

​ 代码如下:

...

private int[] perPageCountChoices = {10, 20, 30, 50};

...

mIndicatorView = (PaginationIndicator) findViewById(R.id.indicator);

mIndicatorView.setTotalCount(99); // 设置数据源总数量即可

mIndicatorView.setPerPageCountChoices(perPageCountChoices); // 选填

mIndicatorView.setListener(new PaginationIndicator.OnChangedListener() {

@Override

public void onPageSelectedChanged(int currentPapePos, int lastPagePos, int totalPageCount, int total) {

Toast.makeText(MainActivity.this, "选中" + currentPapePos + "页", Toast.LENGTH_LONG).show();

}

@Override

public void onPerPageCountChanged(int perPageCount) {

// x条/页 选项改变时触发

}

});

...

​ 相关说明已在代码里注释,详细可参考demo,谢谢

依赖

recyclerview : com.android.support:recyclerview-v7:28.0.0

github地址

源码github

如果觉得对你有所帮助,就喜欢star一下表示下支持呗,谢啦各位看官~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值