zoukankan      html  css  js  c++  java
  • 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.
            }
            
            
            
        }
    }
  • 相关阅读:
    Javascript异步编程的4种方法
    同步编程和异步编程
    关于js 异步回调的一些方法
    array的方法 没记住的
    阮一峰关于reduce 和transduce的博客
    CSS开发小技巧
    提升自己的一个网址
    asm.js 和 Emscripten 入门教程
    Koa -- 基于 Node.js 平台的下一代 web 开发框架
    C#中使用handsonetable的一个例子
  • 原文地址:https://www.cnblogs.com/androidxufeng/p/3687951.html
Copyright © 2011-2022 走看看