PullToRefreshScrollView

来源:互联网 发布:矩阵键盘硬件设计 编辑:程序博客网 时间:2024/05/21 23:28

//////////////////////////

布局

/////////////////////////////////////////////////////////////////////////////////////


<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    xmlns:ptr="http://schemas.android.com/apk/res-auto"    >    <com.handmark.pulltorefresh.library.PullToRefreshScrollView        android:id="@+id/refresh_scroll_view"        android:layout_width="match_parent"        android:layout_height="match_parent"        ptr:ptrAnimationStyle="flip"        ptr:ptrDrawable="@drawable/default_ptr_flip"        ptr:ptrHeaderBackground="#383838"        ptr:ptrHeaderTextColor="#FFFFFF">        <!--scrollView中添加组件 viewPagerListView            注意:在scrollView中只能有一个子孩子-->     <LinearLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical"         >   <com.youth.banner.Banner      android:layout_width="match_parent"      android:layout_height="200dp"      android:id="@+id/banner"      ></com.youth.banner.Banner>         <!--listview引用类里面的  包名+类名-->      <com.example.dszfx.MyListView          android:layout_width="match_parent"          android:layout_height="match_parent"          android:id="@+id/listview"          ></com.example.dszfx.MyListView>                       </LinearLayout>    </com.handmark.pulltorefresh.library.PullToRefreshScrollView></RelativeLayout>/////////////////////////////////////////////// 主函数//////////////////////////////////////////////////////////
public void  prs(){    //1.设置模式    rsv.setMode(PullToRefreshBase.Mode.BOTH);    //2.通过调用getLoadingLayoutProxy方法,设置下拉刷新状况布局中显示的文字 ,第一个参数为true,代表下拉刷新    ILoadingLayout headLables = rsv.getLoadingLayoutProxy(true, false);    headLables.setPullLabel("下拉刷新");    headLables.setRefreshingLabel("正在刷新");    headLables.setReleaseLabel("松开刷新");    //2.设置上拉加载底部视图中显示的文字,第一个参数为false,代表上拉加载更多    ILoadingLayout footerLables = rsv.getLoadingLayoutProxy(false, true);    footerLables.setPullLabel("上拉加载");    footerLables.setRefreshingLabel("正在载入...");    footerLables.setReleaseLabel("松开加载更多");    //3.设置监听事件    rsv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {        @Override        public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {            addToTop();//请求网络数据,并更新listview组件            refreshComplete();//数据加载完成后,关闭header,footer        }        @Override        public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {            addToBottom();//请求网络数据,并更新listview组件            refreshComplete();//数据加载完成后,关闭header,footer        }    });}public void refreshComplete(){    new Handler().postDelayed(new Runnable() {        @Override        public void run() {            rsv.onRefreshComplete();        }    },1000);}
public void setadapter(){    if(adapter==null){        adapter=new MyAdapter(getActivity(),list2);        listview.setAdapter(adapter);    }else{        adapter.notifyDataSetChanged();    }}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

listview引用的类


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package com.example.dszfx;import android.content.Context;import android.util.AttributeSet;import android.widget.ListView;/** * Created by Administrator on 2017/10/24 0024. */public class MyListView extends ListView {    public MyListView(Context context) {        super(context);    }    public MyListView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,                MeasureSpec.AT_MOST);        super.onMeasure(widthMeasureSpec, heightMeasureSpec);    }}




原创粉丝点击