• android SwipeRefreshLayout google官方下拉刷新控件


    下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍

    SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单

    今天就来使用下SwipeRefreshLayout 以后再需要时可以参考.

    首先在布局里面加入SwipeRefreshLayout 布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swiperefreshlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <ListView
                android:id="@+id/tab_topical_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
        </android.support.v4.widget.SwipeRefreshLayout>
    </LinearLayout>

    Activity文件中的代码

    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swiperefreshlayout);
    
            mSwipeRefreshLayout.setColorSchemeResources(R.color.colorRed , R.color.colorGre , R.color.colorBlu);
            mSwipeRefreshLayout.setProgressViewEndTarget(true , 150);
            mSwipeRefreshLayout.setOnRefreshListener(this);

    使用setColorSchemeResources设置下拉刷新的图标颜色可设置四种颜色.

    setProgressViewEndTarget(true , 150)设置距离顶端的距离

    setOnRefreshListener(this)设置监听

    监听方法:

    //滑动手势监听 , 加载数据
        @Override
        public void onRefresh() {
            Toast.makeText(getActivity() , "loding..." , Toast.LENGTH_SHORT).show();
            getDate();//获取数据
            mSwipeRefreshLayout.setRefreshing(false);
        }

    搞定了上面两步就可以使用SwipeRefreshLayout这个控件了.

    看下效果:

    很简单吧.

  • 相关阅读:
    Hash表的查找-C语言
    二叉排序树-C语言
    线性表的查找算法-C语言
    拓扑排序和关键路径
    图结构的创建与遍历-C语言
    MySQL数据库基本脚本命令
    哈夫曼树编码-C语言
    协程简述
    Python多线程编程-Threading库
    Python多进程编程-multiprocessing库
  • 原文地址:https://www.cnblogs.com/wobeinianqing/p/5627319.html
Copyright © 2020-2023  润新知