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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540830.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540830.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540830.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

scala重載無參構造方法_Scala中的無參數方法

scala重載無參構造方法Scala無參數方法 (Scala parameterless method) A method which accepts no parameters from the calling code. It also denotes that there will not be any empty parentheses. These are special types of methods in Scala that are initialized and…

傳統存儲做到極致也驚人!看宏杉科技發布的CloudSAN

傳統存儲陣列首先考慮的是高可靠、高性能。那么在成本上、擴展上、部署上就差。 互聯網企業帶來分布式存儲,擴展上、部署上是優勢了,但是單節點的可靠性差、數據一致性差、IO延遲大、空間浪費嚴重,能耗大。 這兩者的問題,我想很多…

android inflate,Android 關于inflate

通俗的說,inflate就相當于將一個xml中定義的布局找出來.因為在一個Activity里如果直接用findViewById()的話,對應的是setConentView()的那個layout里的組件.因此如果你的Activity里如果用到別的layout,比如對話框上的layout,你還要設置對話框上的layout里的組件(像圖片ImageVie…

keil lic_LIC的完整形式是什么?

keil licLIC:印度人壽保險公司 (LIC: Life Insurance Corporation of India) LIC is an abbreviation of the Life Insurance Corporation of India. It is a public segment insurance and investment group corporation in India that generally deals with life …

“云”上存儲初顯規模 如何架構是關鍵

在安防系統中,存儲設備只是給數據提供存儲空間,數據存儲的意義更多是為了給上層應用提供二次挖掘。目前的智能分析、大數據、圖幀等技術都是基于數據存儲做的數據挖掘。為了將二次挖掘應用的性能提升到最高,在優化分析算法的同時,…

在線圖片轉成html,在線將JPEG 轉換成HTML。 免費將.jpeg 轉換成.html。

描述|介紹JPEG – is a popular graphic format, which is characterized by a high degree of compression, which leads to a decrease in image quality. It uses the technology of encoding of smooth color renditions, providing the ability to reduce the amount of d…

密碼學常用的算法填充模式_密碼學的操作模式

密碼學常用的算法填充模式Modes of operation of a block cipher are procedural rules for a generic block cipher. The different modes of operation result in different properties being achieved which add to the security of the underlying block cipher in the cry…

【干貨】分享總結:MySQL數據一致性

0、導讀 沃趣科技數據庫工程師羅小波為大家全面分析如何保證MySQL的數據一致性。 1、活動總結 羅小波老師從MySQL的崩潰數據恢復安全性、MySQL復制原理及異步&semi sync復制原理、MySQL主從服務器如何保證數據一致性等多方面分析如何保證MySQL的數據一致性。 分享內容滿滿的…

設置html按鈕點擊事件無效果,css怎么設置按鈕不能點擊?

css怎么設置按鈕不能點擊?下面本篇文章就來給大家介紹一下使用CSS設置按鈕不能點擊的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。想要按鈕不能點擊可以通過設置按鈕點擊事件失效來實現;而在CSS中&…

計算機圖形學與幾何造型導論_計算機圖形學導論

計算機圖形學與幾何造型導論歷史 (History) The main forerunner sciences to the development of modern computer graphics were the advances in electrical engineering, electronics, and television that took place during the first half of the twentieth century whe…

android scrollview焦點,scrollview里面的edittext,當它獲得焦點時如何滾動到edittext

在scrollview中有一個edittext。 (并且edittext上方的scrollview中還有其他視圖。)當用戶按下edittext時,鍵盤變得可見,并且scrollview的可見區域變得很小。因為edittext沒有顯示在屏幕上。 (它不會滾動滾動視圖,以便顯示編輯文本。)在用戶按…

Linux中解壓rar文件

Linux平臺默認是不支持RAR文件的解壓,需要安裝linux版本的RAR壓縮軟件,下載地址為:http://www.rarlab.com/download.htm 下載之后進行解壓之后,進入rar目錄,運行make指令進行安裝: [rootlocalhost rar]# ls…

kotlin 查找id_Kotlin程序查找立方體區域

kotlin 查找idA cube has 6 square faces, if edges length is side. Then the area of each square is side2, thus, the area of cube will be 6*sise2. 如果邊的長度為side ,則一個立方體有6個正方形的面。 那么每個正方形的面積是邊2 ,因此&#xff…

Python自動化運維之高級函數

一、協程1.1協程的概念協程,又稱微線程,纖程。英文名Coroutine。一句話說明什么是線程:協程是一種用戶態的輕量級線程。(其實并沒有說明白~)那么這么來理解協程比較容易:   線程是系統級別的,…

android 繼承listview,Android listView 繼承ListActivity的用法

Android listView 繼承ListActivity的用法 在手機中經常有列表方式。如果Activity中只有唯??個List(這也是通常的情況),可以繼承ListActivity來實現。我們用兩個例子來學習List。List例子?:利用Android自帶的List格式步驟?:Android XML文…

計算機圖形學的應用

Some of the applications of computer graphics are, 計算機圖形學的一些應用是 Education and Training 教育和培訓 Use in Biology 用于生物學 Computer-Generated Maps 計算機生成的地圖 Architect 建筑師 Presentation Graphics 演示圖形 Computer Art 電腦美術 Entertai…

html頁面授權碼,spring boot 2.0 整合 oauth2 authorization code授權碼模式

oauth2 authorization code 大致流程用戶打開客戶端后,客戶端要求用戶給予授權。用戶同意給予客戶端授權。客戶端使用授權得到的code,向認證服務器申請token令牌。認證服務器對客戶端進行認證以后,確認無誤,同意發放令牌。客戶端請…

Net設計模式實例之代理模式(Proxy Pattern)

一、代理模式簡介(Brief Introduction) 代理模式(Proxy Pattern)對其他對象提供一種代理以控制對這個對象的訪問。 二、解決的問題(What To Solve) 1、遠程代理 遠程代理,也就是為了一個對象…

c語言存儲類_C編程語言的存儲類

c語言存儲類A variables storage class tells us the following, 變量的存儲類告訴我們以下內容: Where the variables would be stored? 變量將存儲在哪里? What will be the initial of the variable, if the initial value is not specifically ass…

jsonp請求html頁面,JavaScript中的JSON和JSONP

簡單地使用json并不能支持跨域資源請求,為了解決這個問題,需要采用jsonp數據交互協議。眾所周知,js文件的調用不受跨域與否的限制,因此如果想通過純web端跨域訪問數據,只能在遠程服務器上設法將json數據封裝進js格式的…