日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

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

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

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

目錄

功能介紹

效果圖

如何引入

簡單使用

依賴

github地址

功能介紹

支持延遲加載分頁

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

支持加載狀態(tài)改變提示

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

效果圖

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為將要加載的頁碼,即需要加載數(shù)據(jù)的頁

// perPageCount 每頁展示的數(shù)量

//TODO : 此處進行異步數(shù)據(jù)加載

//TODO : 完成加載后通知分頁控件(注意此處應該是在主線程運行),如下

mAdapter.setDatas(nextPagePosition, data);

mPaginationRcv.setState(PaginationRecycleView.SUCCESS);

}

@Override

public void onPerPageCountChanged(int perPageCount) {

// "x條/每頁"Spinner選中值改變時觸發(fā)

}

});

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" // 數(shù)字指示器顯示的數(shù)量,默認是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); // 設置數(shù)據(jù)源總數(shù)量即可

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條/頁 選項改變時觸發(fā)

}

});

...

? 相關說明已在代碼里注釋,詳細可參考demo,謝謝

依賴

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

github地址

源碼github

如果覺得對你有所幫助,就喜歡star一下表示下支持唄,謝啦各位看官~

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。