日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發布時間:2025/3/11 Android 62 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android网页省略分页器,Android轻量级网页风格分页器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

博客同步自:個人博客主頁

輕量級仿網頁風格分頁器,和RecycleView封裝一起配合使用,也可單獨使用,喜歡就star、fork下吧~謝謝

目錄

功能介紹

效果圖

如何引入

簡單使用

依賴

github地址

功能介紹

支持延遲加載分頁

支持單獨分頁器組件使用;同時封裝了RecycleView,可以配合使用

支持加載狀態改變提示

支持自定義數字指示器數量、選中和未選中等樣式

效果圖

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一下表示下支持唄,謝啦各位看官~

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的android网页省略分页器,Android轻量级网页风格分页器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。