android自定义分页组件

组件代码如下:
public class PageControl extends LinearLayout implements OnClickListener{
	private ImageButton firstImg;
	private ImageButton preImg;
	private ImageButton nextImg;
	private ImageButton endImg;
	private TextView totalPageText;
	private TextView curPageText;
	private int numPerPage=10;
	private int curPage=1;
	private int count=0;
	private OnPageChangeListener pageChangeListener; 
	public PageControl(Context context) {
		super(context);
		initPageComposite(context);
	}
	public PageControl(Context context, AttributeSet attrs) {
		super(context, attrs);
		initPageComposite(context);
	}
	public PageControl(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initPageComposite(context);
	}
	private void initPageComposite(Context context){
		this.setPadding(5,5,5,5);
		firstImg=new ImageButton(context);
		firstImg.setId(1);
		firstImg.setImageResource(R.drawable.firstpage);
		firstImg.setPadding(0,0,0,0);
		LayoutParams layoutParam=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		layoutParam.setMargins(0,0,5,0);
		firstImg.setLayoutParams(layoutParam);
		firstImg.setOnClickListener(this);
		this.addView(firstImg);
		preImg=new ImageButton(context);
		preImg.setId(2);
		preImg.setImageResource(R.drawable.prepage);
		preImg.setPadding(0,0,0,0);
		layoutParam=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutP
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的自定义分页组件的示例,使用Vue2实现: ``` <template> <div> <ul class="pagination"> <li :class="{ 'disabled': currentPage === 1 }"> <a href="#" @click.prevent="prevPage"> Previous </a> </li> <li v-for="page in pages" :class="{ 'active': page === currentPage }"> <a href="#" @click.prevent="changePage(page)">{{ page }}</a> </li> <li :class="{ 'disabled': currentPage === totalPages }"> <a href="#" @click.prevent="nextPage"> Next </a> </li> </ul> </div> </template> <script> export default { props: { currentPage: { type: Number, required: true, }, totalPages: { type: Number, required: true, }, maxPagesToShow: { type: Number, default: 5, }, }, computed: { pages() { let pages = []; let startPage = 1; let endPage = this.totalPages; if (this.maxPagesToShow < this.totalPages) { let middle = Math.ceil(this.maxPagesToShow / 2); startPage = Math.max(this.currentPage - middle + 1, 1); endPage = startPage + this.maxPagesToShow - 1; if (endPage > this.totalPages) { endPage = this.totalPages; startPage = endPage - this.maxPagesToShow + 1; } } for (let i = startPage; i <= endPage; i++) { pages.push(i); } return pages; }, }, methods: { changePage(page) { this.$emit('change-page', page); }, prevPage() { if (this.currentPage > 1) { this.changePage(this.currentPage - 1); } }, nextPage() { if (this.currentPage < this.totalPages) { this.changePage(this.currentPage + 1); } }, }, }; </script> <style> .pagination { display: inline-block; } .pagination li { display: inline; padding: 5px 10px; } .pagination li.disabled a, .pagination li.active a { pointer-events: none; color: #777; cursor: default; } </style> ``` 在父组件中引入自定义分页组件并使用,示例代码如下: ``` <template> <div> <table> <!-- 表格内容省略 --> </table> <custom-pagination :current-page="currentPage" :total-pages="totalPages" @change-page="handlePageChange" /> </div> </template> <script> import CustomPagination from './CustomPagination.vue'; export default { components: { CustomPagination, }, data() { return { currentPage: 1, totalPages: 10, }; }, methods: { handlePageChange(page) { this.currentPage = page; // 切换页面数据的方法 }, }, }; </script> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值