Android之官方下拉刷新控件SwipeRefreshLayout

SwipeRefreshLayout 是在V4包里面,首先要先导入V4包,最新的V4包里面才有这控件

首先是布局

 

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"
            android:text="@string/hello_world"  >
            
        </TextView>
        </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

SwipeRefreshLayout 中嵌入一个可滑动的控件,可以是scrollview  也可以是listview  gridview

package com.example.swiperrefreshlayout;

import android.os.Bundle;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.text.SpanWatcher;
import android.view.Menu;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.widget.TextView;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

    SwipeRefreshLayout swiper;
    ObjectAnimator oa;
    TextView text;
    private Interpolator accelerator = new AccelerateInterpolator();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        swiper=(SwipeRefreshLayout) findViewById(R.id.swipe_container);
        swiper.setOnRefreshListener(new listener());
        text=(TextView) findViewById(R.id.text);
        
        //显示或隐藏刷新进度条
        swiper.setRefreshing(false);
        // 设置进度条的颜色主题,最多能设置四种
        swiper.setColorScheme(android.R.color.holo_blue_bright, 
                android.R.color.holo_green_light, 
                android.R.color.holo_orange_light, 
                android.R.color.holo_red_light);
        
        oa=ObjectAnimator.ofFloat(swiper, "rotationY", 0f,-180f);
        oa.setDuration(600);
        oa.setRepeatCount(1);
        oa.setRepeatMode(ObjectAnimator.REVERSE);
        oa.setInterpolator(accelerator);
    //    Animation an=new Animation();
    }
    class listener implements  OnRefreshListener{

        @Override
        public void onRefresh() {
            // TODO Auto-generated method stub
            oa.start();
            
            if(swiper.isRefreshing()){
                text.setText("正在刷新");
            }else{
                text.setText("停止刷新");
            };
            //swiper.
        }
        
        
        
    }
}

 

 

 

 

转载于:https://www.cnblogs.com/androidxufeng/p/3687951.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值