效果如图:

<android.support.v4.widget.SwipeRefreshLayout    android:layout_width="match_parent"    android:layout_height="match_parent"    xmlns:android="http://schemas.android.com/apk/res/android"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:paddingBottom="@dimen/activity_vertical_margin"    android:id="@+id/swipe">    <ScrollView        android:layout_width="match_parent"        android:layout_height="match_parent">        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="match_parent">             <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Random number:"                android:id="@+id/lbl"/>             <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:id="@+id/rndNum"                android:layout_toRightOf="@id/lbl"/>              <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_below="@id/lbl"                android:layout_centerHorizontal="true"                android:layout_marginTop="20dp"                android:text="Swipe to Refresh"                style="@android:style/TextAppearance.Medium"/>           </RelativeLayout>    </ScrollView></android.support.v4.widget.SwipeRefreshLayout>

import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.support.v4.widget.SwipeRefreshLayout;import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;import android.widget.TextView;public class MainActivity extends Activity {private SwipeRefreshLayout swipe_container;private TextView tv;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                swipe_container = (SwipeRefreshLayout) findViewById(R.id.swipe_container);        tv = (TextView)findViewById(R.id.textView1);                swipe_container.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);        swipe_container.setOnRefreshListener(new OnRefreshListener() {            @Override            public void onRefresh() {                tv.setText("正在刷新");                new Handler().postDelayed(new Runnable() {                    @Override                    public void run() {                        tv.setText("刷新完成");                        swipe_container.setRefreshing(false);                    }                }, 5000);            }        });    }}


在listView滑动的时候会有些问题,增加listview的一个监听,如下:
listView.setOnScrollListener(new AbsListView.OnScrollListener() {@Overridepublic void onScrollStateChanged(AbsListView absListView, int i) {}@Overridepublic void onScroll(AbsListView absListView, int firstVisibleItem,int visibleItemCount, int totalItemCount) {if (firstVisibleItem == 0)swipe_container.setEnabled(true);elseswipe_container.setEnabled(false);}});

更多相关文章

  1. Android(安卓)SmartRecyclerView
  2. android内部类
  3. 获得位置信息 android
  4. android 监听电源键
  5. Android的Activity屏幕切换动画(一)-左右滑动切换
  6. Android(安卓)USB状态监控(解决scheme="file")
  7. Android(安卓)滚动条
  8. android的ScrollView的简单使用
  9. Android03_事件处理

随机推荐

  1. adb通过TCP/IP来调试Android设备
  2. Android(安卓)6.0发布大会来了,来看看Andr
  3. android权限机制,你真的了解么
  4. Android能用Linux打败Linux手机吗?
  5. 图解 Android(安卓)View动画中 android:p
  6. Android内核开发:图解Android系统的启动过
  7. Android撬动IT市场的新支点
  8. android中的坐标系以及获取坐标的方法
  9. Android自定义视图二:用Canvas和Paint绘制
  10. Android深度定制化TabLayout:圆角,渐变色,背