android最新上拉載入,下拉重新整理
開發專案過程中基本都會用到listView的下拉重新整理和上滑載入更多,之前大家最常用的應該是pull to refresh或它的變種版吧,google官方在最新的Android.support.v4包中增加了一個新類SwipeRefreshLayout,地址 這個類的作用就是提供官方的下拉重新整理,並且效果相當不錯,而上拉載入更多則用我們自定義的listview,也是相當簡單。
下拉重新整理
簡單的介紹下:
首先它是一個viewgroup,但是它只允許有一個子控制元件,子控制元件能是任何view,使用的時候,所在類實現OnRefreshListener介面,在onRefresh()方法中實現所要完成的任務,
findviewbyid得到SwipeRefreshLayout後,顯示重新整理動畫用SwipeRefreshLayout.setRefreshing(true);取消重新整理動畫用SwipeRefreshLayout.setRefreshing(false);相當簡單。
另外有一些其他的常用方法比如判斷時候正在顯示重新整理動畫,用SwipeRefreshLayout.isShown()。
佈局:
- <android.support.v4.widget.SwipeRefreshLayout
-
android:id="@+id/swip_index"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <com.example.listviewloadmore.LoadMoreListView
- android:id="@+id/listView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
-
android:text
- </com.example.listviewloadmore.LoadMoreListView>
- </android.support.v4.widget.SwipeRefreshLayout>
上拉載入更多
思路:監聽滑動事件並判斷是否到達底部,到達底部的時候,回撥我們定義好的一個方法,從而達到上拉載入更多的目的。 但是具體怎麼監聽和回撥呢,我們不妨看看Button控制元件的點選事件的執行流程,Button繼承textView,textView繼承View 1.實現OnClickListener介面,重寫onClick方法 2.設定Button.setOnClickListener(this)或者new一個介面也一樣的。 檢視View原始碼,我們可得知 View類中有OnClickOistener介面,setOnClickListener方法 那麼我們在我們自己的listview中要實現的步驟狠清楚了 1.myListView繼承listView 2.實現onLoadMore介面 3.在類中宣告onLoadMore介面物件 4.設定點選方法setOnLoadMore 5.在需要的地方呼叫onLoadMore.loadMore方法。 下面附上MyListView原始碼:- package com.example.listviewloadmore;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.widget.AbsListView;
- import android.widget.AbsListView.OnScrollListener;
- import android.widget.ListView;
- publicclass LoadMoreListView extends ListView implements OnScrollListener{
- private View footer;
- privateint totalItem;
- privateint lastItem;
- privateboolean isLoading;
- private OnLoadMore onLoadMore;
- private LayoutInflater inflater;
- public LoadMoreListView(Context context) {
- super(context);
- init(context);
- }
- public LoadMoreListView(Context context, AttributeSet attrs) {
- super(context, attrs);
- init(context);
- }
- public LoadMoreListView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- init(context);
- }
- @SuppressLint("InflateParams")
- privatevoid init(Context context) {
- inflater = LayoutInflater.from(context);
- footer = inflater.inflate(R.layout.load_more_footer,null ,false);
- footer.setVisibility(View.GONE);
- this.addFooterView(footer);
- this.setOnScrollListener(this);
- }
- @Override
- publicvoid onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
- this.lastItem = firstVisibleItem+visibleItemCount;
- this.totalItem = totalItemCount;
- }
- @Override
- publicvoid onScrollStateChanged(AbsListView view, int scrollState) {
- if(this.totalItem == lastItem&&scrollState == SCROLL_STATE_IDLE){
- Log.v("isLoading", "yes");
- if(!isLoading){
- isLoading=true;
- footer.setVisibility(View.VISIBLE);
- onLoadMore.loadMore();
- }
- }
- }
- publicvoid setLoadMoreListen(OnLoadMore onLoadMore){
- this.onLoadMore = onLoadMore;
- }
- /**
- * 載入完成呼叫此方法
- */
- publicvoid onLoadComplete(){
- footer.setVisibility(View.GONE);
- isLoading = false;
- }
- publicinterface OnLoadMore{
- publicvoid loadMore();
- }
- }
程式碼不是很複雜,認真看一定能看明白。 底部正在載入佈局程式碼
- <?xmlversion="1.0"encoding="utf-8"?>
- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/load_more_footer"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true">
- <ProgressBar
-
相關推薦
android最新上拉載入,下拉重新整理
開發專案過程中基本都會用到listView的下拉重新整理和上滑載入更多,之前大家最常用的應該是pull to refresh或它的變種版吧,google官方在最新的Android.support.v4包中增加了一個新類SwipeRefreshLayout,地
XListView上拉載入,下拉重新整理
1.MainActivity頁面 public class MainActivity extends AppCompatActivity { private XListView xListView; private int page; private NewsAdapter adapt
使用vue-mint-ui 上拉載入,下拉重新整理效果
剛開始進入公司,搞得是vue開發的微信公眾號,花了好幾天做了一個這個效果,自己都笑哭了。做了這麼長時間。 <!-- <div class="dataSet" v-for="(item,index) in bulletinList" :
iscroll.js 移動端上拉載入,下拉重新整理功能實現
如下圖所示,我需要做一個上拉載入,下拉重新整理的功能: 首先在 html 中引用這個外掛: <script src="/js/common/iscroll.js"></script> 然後插入我們的資料: <d
功能強大的RecyclerView實現 (單/多子項佈局載入,上拉載入,下拉重新整理,左劃刪除)
先看效果,可以像普通recyclerView那樣只加載一種列表子項,也可以同時載入不同的列表子項,已經寫好了常用必備的功能:正常的適配渲染,上拉載入,下拉重新整理,左劃刪除。 核心是XRefreshView+MultiTypeAdapter兩者組合使用,搭
MUI上拉載入,下拉重新整理
前言:這是最近專案中的一個新聞列表 1.DOM容器 這裡只貼主要的程式碼 <div id="refreshId" class="mui-content mui-scroll-wrapper" style="background-col
上拉載入,下拉重新整理列表資料,多條目列表,預設圖圓角
package yxr.com.wekk2_lixie; //viewpager+Fragment滑動 import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import
微信小程式--刷臉認證(人臉識別,上拉載入,下拉重新整理)
//獲取應用例項 const app = getApp() var page = 1; var isfinish = false;//載入完畢 function loadmore(that){ if(isfinish) return; wx.showLoading({ title: '正在載入
移動端上拉載入,下拉重新整理效果Demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="renderer" content="webkit">
【前端】dropload 上拉載入,下拉重新整理(不推薦使用)
dropload 上拉載入,下拉重新整理 dropload 指令碼 2018-4-18 測試:不能正常執行 蘋果6版本是8.3(12f70) 低版本安卓 5.1 得 瀏覽器不支援,微信最
vue mint-ui 上拉載入,下拉重新整理
1.html部分 <div class="detail" ref="wrapper"> <mt-loadmore :top-method="loadTop" :bottom-method="loadBottom" @bottom-status-chan
XlistView 上拉載入,下拉重新整理
public class MainActivity extends Activity implements IXListViewListener { private XListView xListView; private String uul = "http://www.oschina.net/act
react專案中通過 iscroll 實現上拉載入,下拉重新整理
基於 iscroll 實現的 react 元件 第一步:引入外掛 npm install reactjs-iscroll --save 可在專案下的package.json檔案內dependencies下看到安裝好的外掛版本; 第二步:在專案中使用 import iS
PullToRefreshListView上拉載入,下拉重新整理 重新整理網路資料 簡單實現ListView顯示網路資料
1、依賴: compile 'com.google.code.gson:gson:2.6.2' compile 'com.github.userswlwork:pull-to-refresh:1.0.0' 2、許可權: <uses-permission andro
andbase框架實現上拉載入,下拉重新整理和自定義旋轉動畫的方式
1、今天做列表時,需求上需要做一個下拉重新整理,下拉載入更多的功能,就上網找了一些例子,由於我原來用的就是andbase框架,就還是用它原來寫的了。其中同事給我推薦另一個框架BGARefreshLayout-Android,下載地址https://github.com/bin
react-native之上拉載入,下拉重新整理元件封裝
react-native 自定義封裝重新整理元件 幾個月沒寫部落格了,最近一直在寫react 和react-native,前幾天剛發了一版基於react-native混合開發的App,這幾天趕快總結下。 寫過java的同學,再去學習react和rea
vant 上拉載入和下拉重新整理
1.使用vant中的list和PullRefresh元件 import { PullRefresh,List } from 'vant'; Vue.use(PullRefresh).use(List); 2.程式碼demo <van-pull-ref
PullToRefresh上拉載入和下拉重新整理
1—新增依賴 implementation ‘com.github.userswlwork:pull-to-refresh:1.0.0’ implementation ‘com.google.code.gson:gson:2.8.5’ 2— 新增許可權 3—添加布局 <
vue-上拉載入、下拉重新整理元件
vue在移動端開發過程中,上拉載入、下拉重新整理是頁面的基本需求,現在給大家介紹一種基於touch事件封裝的重新整理元件。 元件支援傳參、傳遞事件、請求成功非同步回撥、上拉與觸底觸發載入或重新整理。 父子元件間的通訊 這裡我們有兩個頁面,父元件note.vue與重新整理元件baseScroll.vue。
微信小程式學習(18) —— 上拉載入和下拉重新整理
在微信小程式上實現下拉重新整理、上拉載入的效果 使用系統提供的onPullDownRefresh、onReachBottom這2個事件, 前提需要在app.json或page.json配置檔案中設定,才能使用。 app.json是全應用的頁面都可以使用該事件