zoukankan      html  css  js  c++  java
  • 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这个控件了.

    看下效果:

    很简单吧.

  • 相关阅读:
    base64 c/c++实现
    分段,分页图 http://www.joenchen.com
    CPUID讲解
    密码HASH特点
    C++ 编译器的函数名修饰规则
    exploit已完成,但没有创建会话exploit completed, but no session was created
    获取批处理文件所在路径
    dos/bat批处理教程——第四部分:完整案例
    第三部分:批处理与变量
    第二部分:特殊的符号与批处理
  • 原文地址:https://www.cnblogs.com/wobeinianqing/p/5627319.html
Copyright © 2011-2022 走看看