自定义页码显示控件PageNumberView

实现效果

这里写图片描述

上述效果使用了ViewPager+自制的PageNumberView实现的。下面来介绍一下具体实现:

首先是布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:gravity="center"
    android:orientation="horizontal">

    <Button
        android:id="@+id/btPrevPage"
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:background="@drawable/page_number_selector_btn"
        android:text="上一页" />

    <Button
        android:id="@+id/btFirstPage"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/page_number_selector_btn"
        android:text="首页" />


    <RadioGroup
        android:id="@+id/rgPageNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rbFirst"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/page_number_selector_radiobutton"
            android:button="@null"
            android:gravity="center"
            android:text="1" />

        <RadioButton
            android:id="@+id/rbSecond"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/page_number_selector_radiobutton"
            android:button="@null"
            android:gravity="center"
            android:text="2" />

        <RadioButton
            android:id="@+id/rbThird"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/page_number_selector_radiobutton"
            android:button="@null"
            android:gravity="center"
            android:text="3" />

        <RadioButton
            android:id="@+id/rbFourth"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/page_number_selector_radiobutton"
            android:button="@null&#
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
print.js 是一个用于自定义打印页面的 JavaScript 库。它提供了一种简单的方式来自定义打印页面的样式和内容,包括自定义页码。 要使用 print.js 自定义页码,你可以按照以下步骤进行操作: 1. 引入 print.js 库:在 HTML 文件中引入 print.js 库的 JavaScript 文件。 2. 创建打印按钮:在页面上创建一个按钮,用于触发打印功能。 3. 编写打印功能代码:在 JavaScript 文件中编写打印功能的代码。可以使用 print.js 提供的 API 来自定义打印页面的样式和内容。 4. 自定义页码:使用 print.js 的 API 来自定义页码。可以通过设置页眉或页脚的内容来显示页码,也可以通过设置 CSS 样式来调整页码的位置和样式。 以下是一个简单的示例代码,演示如何使用 print.js 自定义页码: ```html <!DOCTYPE html> <html> <head> <title>Print Page with Custom Page Numbers</title> <script src="print.js"></script> </head> <body> <h1>Print Page with Custom Page Numbers</h1> <button onclick="printPage()">Print</button> <script> function printPage() { // 使用 print.js 的 API 来自定义打印页面 printJS({ printable: 'body', header: '<h1>Custom Header</h1>', footer: '<h3>Page {pageNumber} of {totalPages}</h3>', style: 'h1 { color: red; }', }); } </script> </body> </html> ``` 在上面的示例中,我们使用了 print.js 的 `printJS` 函数来触发打印功能。通过设置 `printable` 参数为 `'body'`,我们指定了要打印的内容为整个页面的内容。然后,我们使用 `header` 参数来设置页眉的内容,使用 `footer` 参数来设置页脚的内容,并在其中使用 `{pageNumber}` 和 `{totalPages}` 占位符来显示页码。最后,我们使用 `style` 参数来设置打印页面的样式。 希望以上信息能够帮助到你!如果你还有其他问题,请继续提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值