麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

SwipeToLoadLayout

2019-11-09 19:04:09
字體:
來源:轉載
供稿:網友

為什么選擇SwipeToLoadLayout?

首先看效果,框架中幫我們實現了幾個主流的刷新效果,Twitter style,JD style,google style,Yalantis style,demo也下載下來看了,真不錯,還支持各種自定義,自定義頭部和尾部,頭部還分classic,above,blow,scale四種類型,還有自動刷新的效果,體驗也很流暢。

再看代碼,刷新,加載各一個接口實現,頭部和尾部也都是用接口實現,遵循設計模式的依賴倒轉原則原則(針對抽象而不是針對具體編程),所以才能具備那么高可塑性,我們要做的就是實現接口里面的內容就可以輕松寫一個刷新效果,就像使用baseAdapter一樣,無論什么數據,什么樣式,都可以輕松實現。

接著看功能,支持各種View和ViewGroup(ListView,ScrollView,RecyclerView,GridView,WebView,Linearlayout,RelativeLayout,FrameLayout,ImageView,TextView等)的刷新和加載,還支持自動刷新,手動刷新,自動加載,手動加載,禁止刷新,禁止加載等操作,完全滿足需求。

最后,說的這么好,有沒有經過測試呢?當然了,口說無憑,帶大家實現一個。

通過SwipeToLoadLayout實現一個刷新加載的效果

1、如何集成

Step 1. Add the JitPack repository in your build.gradle at the end of repositories:

repositories { maven { url "https://jitpack.io" }}

Step 2. Add the dependency in the form

dependencies { compile 'com.github.aspsine:SwipeToLoadLayout:v1.0.0'}

2,開始自定義刷新效果

swipeToLoadLayout提供了一套接口,刷新的頭部自定義一個View實現SwipeTrigger和SwipeRefreshTrigger就行了,刷新的尾部自定義一個View實現SwipeLoadMoreTrigger和SwipeTrigger,頭部實現代碼:

public class CustomRefreshHeadView extends TextView implements SwipeRefreshTrigger, SwipeTrigger { public CustomRefreshHeadView(Context context) { super(context); } public CustomRefreshHeadView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomRefreshHeadView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void onRefresh() { setText("正在拼命加載數據..."); } @Override public void onPRepare() { } @Override public void onSwipe(int i, boolean b) { setText("釋放刷新"); } @Override public void onRelease() { } @Override public void complete() { setText("刷新成功"); } @Override public void onReset() { }}

xml中使用

注意,swipetoloadlayout中布局包裹的View id是指定的,不能亂改,否則找不到<item name="swipe_target" type="id" />刷新目標<item name="swipe_refresh_header" type="id" />刷新頭部<item name="swipe_load_more_footer" type="id" />刷新尾部

<?xml version="1.0" encoding="utf-8"?><com.aspsine.swipetoloadlayout.SwipeToLoadLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/swipeToLoad" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.yyydjk.swipetorefreshdemo.MainActivity"> <com.yyydjk.swipetorefreshdemo.CustomRefreshHeadView android:id="@+id/swipe_refresh_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="20dp" /> <TextView android:id="@+id/swipe_target" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary" android:gravity="center" android:text="Hello World!" /></com.aspsine.swipetoloadlayout.SwipeToLoadLayout>

代碼中調用

CustomRefreshHeadView refreshHeadView = new CustomRefreshHeadView(this);refreshHeadView.setPadding(20,20,20,20);refreshHeadView.setGravity(Gravity.CENTER);refreshHeadView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));swipeToLoadLayout.setRefreshHeaderView(refreshHeadView);

就這么簡單,看下演示效果,做的丑了點,以后有時間弄個精致點的

swipeToRefresh.gif

轉自:http://www.jianshu.com/p/d69ae409a52c

好吧,讓我們再來看個栗子:

Step 1. Create an Simple RefreshHeaderView

public class RefreshHeaderView extends TextView implements SwipeRefreshTrigger, SwipeTrigger {    public RefreshHeaderView(Context context) {        super(context);    }    public RefreshHeaderView(Context context, AttributeSet attrs) {        super(context, attrs);    }    @Override    public void onRefresh() {        setText("REFRESHING");    }    @Override    public void onPrepare() {        setText("");    }    @Override    public void onMove(int yScrolled, boolean isComplete, boolean automatic) {        if (!isComplete) {            if (yScrolled >= getHeight()) {                setText("RELEASE TO REFRESH");            } else {                setText("SWIPE TO REFRESH");            }        } else {            setText("REFRESH RETURNING");        }    }    @Override    public void onRelease() {    }    @Override    public void onComplete() {        setText("COMPLETE");    }    @Override    public void onReset() {        setText("");    }}

Step 2. Create an Simple LoadMoreFooterView

public class LoadMoreFooterView extends TextView implements SwipeTrigger, SwipeLoadMoreTrigger {    public LoadMoreFooterView(Context context) {        super(context);    }    public LoadMoreFooterView(Context context, AttributeSet attrs) {        super(context, attrs);    }    @Override    public void onLoadMore() {        setText("LOADING MORE");    }    @Override    public void onPrepare() {        setText("");    }    @Override    public void onMove(int yScrolled, boolean isComplete, boolean automatic) {        if (!isComplete) {            if (yScrolled <= -getHeight()) {                setText("RELEASE TO LOAD MORE");            } else {                setText("SWIPE TO LOAD MORE");            }        } else {            setText("LOAD MORE RETURNING");        }    }    @Override    public void onRelease() {        setText("LOADING MORE");    }    @Override    public void onComplete() {        setText("COMPLETE");    }    @Override    public void onReset() {        setText("");    }}

Step 3. Edit activity layout xml

<?xml version="1.0" encoding="utf-8"?><com.aspsine.swipetoloadlayout.SwipeToLoadLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/swipeToLoadLayout"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.aspsine.swipetoloadlayoutdemo.MainActivity">    <com.aspsine.swipetoloadlayoutdemo.RefreshHeaderView        android:id="@id/swipe_refresh_header"        android:layout_width="match_parent"        android:gravity="center"        android:layout_height="100dp" />    <ListView        android:id="@id/swipe_target"        android:layout_width="match_parent"        android:layout_height="match_parent" />    <com.aspsine.swipetoloadlayoutdemo.LoadMoreFooterView        android:id="@id/swipe_load_more_footer"        android:layout_width="match_parent"        android:gravity="center"        android:layout_height="100dp" /></com.aspsine.swipetoloadlayout.SwipeToLoadLayout>

Note:

refresh header view android:id="@id/swipe_refresh_header"target view android:id="@id/swipe_target"load more footer view android:id="@id/swipe_load_more_footer"

Step 4. Write java code

public class MainActivity extends AppCompatActivity implements OnRefreshListener, OnLoadMoreListener {    SwipeToLoadLayout swipeToLoadLayout;    ArrayAdapter<String> mAdapter;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        swipeToLoadLayout = (SwipeToLoadLayout) findViewById(R.id.swipeToLoadLayout);        ListView listView = (ListView) findViewById(R.id.swipe_target);        swipeToLoadLayout.setOnRefreshListener(this);        swipeToLoadLayout.setOnLoadMoreListener(this);        mAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_expandable_list_item_1);        listView.setAdapter(mAdapter);        autoRefresh();    }    @Override    public void onRefresh() {        swipeToLoadLayout.postDelayed(new Runnable() {            @Override            public void run() {                swipeToLoadLayout.setRefreshing(false);                mAdapter.add("REFRESH:/n" + new Date());            }        }, 2000);    }    @Override    public void onLoadMore() {        swipeToLoadLayout.postDelayed(new Runnable() {            @Override            public void run() {                swipeToLoadLayout.setLoadingMore(false);                mAdapter.add("LOAD MORE:/n" + new Date());            }        }, 2000);    }    private void autoRefresh() {        swipeToLoadLayout.post(new Runnable() {            @Override            public void run() {                swipeToLoadLayout.setRefreshing(true);            }        });    }}demo地址:https://github.com/Aspsine/SwipeToLoadLayout.git哈哈,這下應該沒問題啦!參考文檔:https://github.com/Aspsine/SwipeToLoadLayout/wiki/Quick-Setup
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲视频在线观看免费 | 黄污在线观看 | 国产亚洲精品久久久久5区 日韩一级片一区二区三区 国产精品久久久久av | 欧美日韩在线视频一区 | 国产大片在线观看 | 宅男噜噜噜66国产免费观看 | 免费毛片a线观看 | 爱福利视频网 | 久久精精 | 日本68xxxx | 久久久国产一区二区三区 | 亚欧美一区二区 | 午夜精品成人一区二区 | 国产一区二区免费 | 精品一区二区三区免费毛片 | 国产999在线 | av在线1| 久精品久久| 91成人免费在线视频 | videos韩国| www.9191.com| 免费在线观看国产精品 | 看国产一级毛片 | 视频一区二区三区在线 | 香蕉成人在线观看 | 日本在线不卡一区二区三区 | 精品国产一区二区三区成人影院 | 国产亚洲精品久久久久久大师 | 国产精品刺激对白麻豆99 | 男女一边摸一边做羞羞视频免费 | 日韩一级电影在线观看 | 国产欧美精品一区二区三区四区 | 斗罗破苍穹在线观看免费完整观看 | 午夜小电影| 精品三区视频 | 特级西西444www大精品视频免费看 | 亚洲视频综合网 | 高潮娇喘嗯啊~文字 | 国产一级在线免费观看 | 99视频有精品视频高清 | 黄色网址在线免费 |