pulltorefesh框架android-pulltorefresh是一个强大拉动刷新_第1页
pulltorefesh框架android-pulltorefresh是一个强大拉动刷新_第2页
pulltorefesh框架android-pulltorefresh是一个强大拉动刷新_第3页
pulltorefesh框架android-pulltorefresh是一个强大拉动刷新_第4页
pulltorefesh框架android-pulltorefresh是一个强大拉动刷新_第5页
免费预览已结束,剩余40页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PullToRefesh框ListView、GridView、ExpandableListView、 ger、WebView、pulltorefresh项创建PullToRefreshProject项其他AndroidStudio导入 此时会报错,先不用-Project+- PropertiesSigningIFlavorsIBuildTypesIDependencies.ISDKLocationDeveloperService口

CompileSdkVersion匠但竺droid4.1[Jelly BuildTools 匠产librarylgnoreAssetsIncrementalDex SourceCompatibility仁回Compatibility亡-Project|+- PropertiesISigningIFlavorsIBuildTypesDependenciesSDKLocation|

.:.

(mdude=[*Jar] DeveloperService.support:appoompat-v7:23.2.0Notications

个士.:.完成^-values下的colors.xml与styles.xml直接提供,drawable下 直接提LineaLyouxmlns:android="http://s /apk/res/androidxln:tl"t:/ android:layoutwidth="matchparent"android:layoutheight="matchaenadrdoravctools:context=".MainActivity"utoandroid:id="@+id/btnpullLteandroid:layoutwidth="matchprnandroid:layoutheight="wrapntntnoi:nik"nliandroid:text="PullToRefreshListView"utoandroid:id="@+id/btnpulldiandroid:layoutwidth="matchpeandroid:layoutheight"racnentandoCbnCandroid:text="PullToRefreshGridView"utoandroid:id="@+id/btnpullExpandlLstViwandroid:layoutwidth="matchaetandroid:layoutheight"racnentandoCbnCandroid:text="PullToRefreshExpandableListView"utoandroid:id="@+id/btnpullSroVewandroid:layoutwidth="matchprnandroid:layoutheight="wrapntntnoi:nik"nliandroid:text="PullToRefreshScrollView"utoandroid:id="@+id/btnpullbeandroid:layoutwidth="matchpeandroid:layoutheight"racnentandoCbnCandroid:text="PullToRefreshWebView"LnrLyutpliclassMainActivityxe tivitypotevionCreate(Bundle{superCvdnn;ntt(lyactivityn}blivobtnClick(View{sit(v.getId())caseR.id.btnpulLwIntentintent1=newthis,ulTohiViwAtiyclassrkcasebtnpullwIntentintent2=newthis,uloRhiwctyclass);rkcasedbtnpullExpandableListViewIntentintent3=newthis,lTRfreEpdlLitiewAv.lrkcasebtnpullrewIntentintent4=newthis,PullToRefreshScrollViewActivity.class);rkcaseibtpullIntentintent5=newthis,PullToRefreshWebViewActivity.class);rk}}}layout/activitypulltorefreshxmlversion="1.0"encoding="utf-lveLayoxmlns:android="http://s /apk/res/androidxnptrtp/ u:awidth=":laytheight="match:rentaton"ertikullerh.rlTrhLia:id="@+id/puaa:layoutwidth="matchaa:layoutheight="matchpntaileraptr:ptrDrawable="@mipmap/icunher:eBd"pedo"Fp:Vwxnbd"r:r"eiw"DDptr:ptrScrollingWhileRefreshingEnabled="true"/><!-ptr是pullToRefresh的配置属性使用是需要添加 ptr:ptrAnimationStyle=""图标动画取值:flip:翻转rotate旋转ptr:ptrHeaderBackground=""上拉下拉时头部的背景色 上拉下拉时文字颜色 ptristexasbed决定了eader,ootr以何种方式加入uRefshsVew,ue为eadVew方式加入,就是滚动时刷新头部会起滚动。xie

在onCreate里面写:pulllv.setMode(Mode.BOTH);//设置你需要的模式andoandoandandoandoandoandoandoando:layoutwidth="wrapce:layoutheight="wann:layoutet"t:text="暂无数据":textSize="20sp"eatvLulayout/pulltorefreshlistviewxmlversion="1.0"encoding="utf-LineaLyouxmlns:android="http://s /apk/res/androidandroid:layoutwidthmatchpn"android:layoutheight="matchaenndr:ren""xieandroid:id="@+id/tvlandroid:layoutwidth="wrapcnenandroid:layoutheight="wrapntntntx"Ad"Aniti"18android:textStyle="bod/>xieandroid:id="@+id/tvteandroid:layoutwidth="wrapctetandroid:layoutheight"racnentandroid:layoutmarginTop="5dp":txEd"7andee"18android:textStyle="bold"LnrLyutpliclassPullBeanpivtStringtitle;pivStringcontentpbString{return}pbvoidsetTitle(String{tisit=}bliString{returncontent}bvosetContent(String{hisnent=}bliString{return"PullBean{+}}

"tile+title+\'",onent="+onte+'\ubcclassMyBaseAdapterxen{ ist<PullBean>bMyBaseAdapter(List<PullBean>{tislis=}pbint{return}pubcObjectgetItem(int{return}pubclonggetItemId(int{return}uliViewgetView(intposition,ViewconvertView,ViewGroupparent)ViewHolderif(convertView==null)convertView=ewie,viewHolder=newViewHolder(convertView);}elseviewHolder=(ViewHolder)}PullBeanbean=list.get(position);viewHolder.tvtitl.setText(bean.getTitle());viewHolder.tvcontent;return}classViewHolderTextViewtvtitle,tvntpliViewHolder(ViewconvertView)tvtitle=(TextView)convertView.findViewById(R.id.tvtvnn=(TextView)onvtifndiBdRidtvonent}}//在头部增加,这个是下拉刷blivoadd(PullBean{lista,}//在尾部增加,这个是上拉加blivoaddLast(PullBean{}}PullToRefreshListView测试CreatedbyHuzaonpliclassPullToRefreshListViewActivityxd ptivityiatPullToRefreshListViewll;iatTextViewtempty;privaist<PullBean>list=null;pivMyBaseAdapterape=null;potevionCreate(Bundle{superCvdnn;(activitpulltorefreshse);initRefreshListen();//初始化下拉与上拉initItemClickListen();//初始化条目点击initScrollListen();//初始化滚动initLastItemVisiableListen();//当用户拉到底时调用}iatvoinitLastItemVisiableListen()pulllvLILrnePullToRefreshBase.OnLastItemVisibleListener()//当用户拉到底时调publicvoidonLastItemVisible()oatTuReehVeAcvythis"到最后了!",Toast.LENGTHSHORT}

ia initScrollListen()//与listview样pulllvtSlLinrnewAbsListView.OnScrollListener()SCROLLSTATETOUCHSCROLLSCROLLSTATEFLING手指做了抛的动作(手指离开屏幕前,用力滑了下SCROLLSTATEIDLE止滚*blvionScrollStateChanged(AbsListViewview,iscrollState)}lvionScroll(AbsListViewview,int VisibleItem,intvisibleItemCount,intotalItemCount){}}iatvoinitView()pulllv=(PullToRefreshListView)fy(dpulllv);tve=(TextView)findViewById(R.id.tvempyILoadingLayoutstartLables=pulllviyttrue,false);startLables.setPullLabel("下拉刷新...");//刚下拉时,显示的提示startLables.setRefreshingLabel("正在刷新...");//刷新时startLables.setReleaseLabel("放开刷新...");//下拉达到距离时,显示的提示//DateUtils.FORMATABBREVALLStringlabel=DateUtils.formatDateTime(this,System.currentTimeMillis(),FORMASHOWTI|FORMATSHOWDATE|tUiFORMATABBREVALL);ILoadingLayoutendLabelspulllvtaiatfalsetrue);endLabels.setPullLabel("上拉加载...");}pvatiinitData()list=newArrayList<PullBean>();forini=0;i<30;i++){PullBeanbean=newPullBean();"Title"+i);"Content"+i);}}iatvoinitAdapter()ate=newMyBaseAdapter(list); pulllv.setEmptyView(tvey}iatvoinitRefreshListen()//设置上拉与下pulllvrLrnePullToRefreshBase.OnRefreshListener2<ListView>()下拉plivoonPullDownToRefresh(PullToRefreshBase<ListView>refreshView)刷新new}上拉plivoonPullUpToRefresh(PullToRefreshBase<ListView>{new}}iatvoinitItemClickListen()pulllvILrne{blvonItemClick(AdapterView<?>parent,Viewview,intposition,on{PullBeanbean=To.tlloeehiteivtythisbean.toString(),Toast.LENGTHSHORT}

个classPullDownToRefreshDataetn k<Void,Void,Void>rect nBackground(Void...{PullBeanbean=newPullBean();bean.setTitle("我是刷新数据...");bean.setContent("我是刷新内容 模拟//增加在头datr turn}rectvionPostExecute(VoidaVoid)完成 //通知adapter更adapter}}//开个异步任务classPullUpToRefreshDataeen k<Void,Void,Void>rect nBackground(Void...params)intsize=list.size();intend=size+10;for(inti=size;i<end;{PullBeanbean=newPullBean();"Title"Conten+adapter}turn}recvionPostExecute(VoidaVoid)完成 //通知adapter更adapter}}}layout/activitypulltorefreshxmlversion="1.0"encoding="utf-liveLayoxmlns:android="http://s /apk/res/androidxnptrtp/ uandroid:layoutwidth="matchpandroid:layoutheight="mcparent"o.hadar.loeflbarPllReedieandroid:id="@+dplgv"android:layoutwidth="matchprnandroid:layoutheight="matchpen"d:mdno:rvt"enrni:hinScin"1dandroid:numColumns="autofit"d:e"lmd:vrg":r"ptr:ptrDrawable="@mipmap/icne<!-

android:numColumns="autofit"//单行显示九宫格个数自适应android:horizontalSpacing="1dp"//九宫格水平间距android:verticalSpacing="1dp"//九宫格垂直间距android:stretode="columnWidth"//缩放与列宽大小同步个间隔空xieandroid:id="@+id/tvandroid:layoutwidth="wrapceandroid:layouthgh="wcteandroid:layoutcenterInParent="tueado:ex"暂无数据"android:textSize="20sp"eatvLuxmlversion="1.0"encoding="utf-liveLayoxmlns:android="http://s /apk/res/androidandroid:layoutwidthmatchpn"android:layoutheight="wrapctetmaeea"android:layoutwidth="matchpeandroid:layoutheight="150dp"android:src="@drawable/one"xiei"android:layoutwidth="wrapctetandroid:layoutheight"ranttandroid:layoutalignLeft="@+id/img"android:layoutalignTop="@+id/imgandroid:layoutmarginLeft="20dp"android:layoutmarginTop="20dp"ad:e"ae"a000android:textSize="20sp"/>xieadrii"iteandroid:layoutwidth="wrapceandroid:layouthgh="wcteandroid:layoutalignLeft="@+id/name"android:layoutbelow="@id/name"android:layoutmarginTop="10dp"ad:e"andeCr"0aandroid:textSize="16sp"/>xieadi"@eandroid:layoutwidth="wrapceandroid:layouthgh="wcteandroid:layoutalignLeft="@+id/name"android:layoutbelow="@id/title"android:layoutmarginTop="10dp"ad:e"andeCr"000android:textSize="15sp"/>eatvLupliclassJsonBeanrvtintrvtStringname;pvatStringimageurl;pvatStringtitle;pvaongupdatedat;pliBeaninid,Stringname,Stringimageurl,Stringtitle,nupdated{this.id==name;this.imageurl=imageurl;this.title=title;this.updatedat=updated}liint{tur}puboisetId(int{this.id=}pliString{reur}ubcvosetName(String{=}pliStringgetImage{reurimage}pubiosetImageurl(Stringimage{this.imageurl=image}pubString{ur}pubvosetTitle(String{this.title=}pubiogetUpdated{etrupdated}pubiosetUpdatedlongupdated{this.updatedat=updated}}pubiclassHttpUtilsplistaticLinkedList<JsonBean>getJsonBeanListByUrl(Stringparam)toIOException,{URLurl=newHttpURLConnectionconn=(HttpURLConnection)url.openConnection();"GET"if(conn.getResponseCode()==200)InputStreaminStream=conn.getInputStream();StringjsonStr=convertInStreamToStr(inStream);//解析tur}rtun}piattLinkedList<JsonBean>parseJson(StringjsonStr)how{LinkedList<JsonBean>list=newLinkedList<JsonBean>();JSONArrayjsonArray=newJSONArray(jsonStr);for(inti=0;i<jsonArray.length();i++)JSONObjectobject= id=Stringname="name"Stringimageurl=t"imageurl");Stringtitle=r"title);longupdatedat=object.getLong("updatedlist.add(newJsonBean(id,name,imageurl,title,updated}rtun}ritttiStringconvertInStreamToStr(InputStreaminStream)tow{ByteArrayOutputStreambaos=newintlen=byebuffer=newbytewil((len=inStream.read(buffer))>{baos.write(buffer,,len);}tur}}pliclassChanYouJiAdapterend{ inkedList<JsonBean>rvayoutInflaternrpliChanYouJiAdapter(LinkedList<JsonBean>list,Context{thslt=thsnlaer=(LayoutInflater)context.getSystemService(Context.LAYOUTINFLATERSERVICE}pubint{tur}ubObjectgetItem(int{rtr}ublogetItemId(int{rtr}ubcViewgetView(intposition,ViewconvertView,ViewGroup{ViewHolderif(convertView==null)convertView=inflaterpulltorefreshgridviee,null);viewHolder=newViewHolder(convertView);}sviewHolder=(ViewHolder)}JsonBeanbean=list.get(position);odnamebmStringdate=DateUtils.formatDateTime(parent.getContext(),bean.getUpdatedat(),UFORMTSHOWTI|DFORMASHOWDATE|FORMATABBREVALL);Picasso.with(parent.getContext()).load(bean.getImageimger}staticclassViewHolderImageViewgTextViewname,title,ubcViewHolder(ViewconvertView)i=(ImageView)cetieidieRidim);name=(TextView)coneteideydRdname);title=(TextView)convertView.findViewById(R.id.title);da=(TextView)convertView.findViewById(R.id.date);}}}pliclassLoadDataAsynxend k<String,Integer,{paProgressDialogpd;pvatContextcontext;rvtResultListenerlistener;pliLoadDataAsyn(Contextcontext,ResultListener{thscontext=tst =}pubitracResultListenerplivisetResult(LinkedList<JsonBean>}eevi{pd=newcontextpd.setTitle("数据pd.setMessage("数据 }rtete nBackground(String...params)tryer}cac(IOException|JSONException{}rtun}rtetevo inkedList<JsonBean>jsonBeans)if(jsonBeans!={listener}//关闭进度进条}}ubcclassPullToRefreshGridViewActivityeend tivityplentLoadDataAsyn.ResultListener{pvatttifinalStringJSONPATH= /api/articles.json?page="pvatPullToRefreshGridViewpgvpiaTextViewtvemypiainkedList<JsonBean>piaChanYouJiAdapterde=nullpiaintcurrPage=1;vtoleaDwl=al;//如果是加载则为false,如果是刷新则是eevionCreate(Bundle{super.onCreate(savedInstanceState);setContentView(R.layout.activitypulltorefreshgie);//异步任务加newthisthisJSONPATH+currPageplgv.setOnRefreshListener(newPullToRefreshBase.OnRefreshListener2<GridView>()下拉ubcvoonPullDownToRefresh(PullToRefreshBase<GridView>{upDown=rcurrPage= Peythis eeGcythisJSO ATH+}上拉ubcvoonPullUpToRefresh(PullToRefreshBase<GridView>{upDown=l Peythis eeGcythisJSO ATH+}}pvatiinitView()ulgv=(PullToRefreshGridView)findViewById(R.id.pulltvpt=(TextView)findiBdR.tvpyILoadingLayoutstartLables=ulgvtaiattruefalse);startLables.setPullLabel("下拉刷新...");//刚下拉时,显示的提示startLables.setRefreshingLabel("正在刷新...");//刷新startLables.setReleaseLabel("放开刷新..."拉达到距离时Stringlabel=DateUtils.formatDateTime(this,System.currentTimeMillis(),DateUtils.FORMATSHOWIM|DateUtils.FORMATSHOWDATE|DateUtils.FORMATABBREVALL);ILoadingLayoutendLabelspullgvonfalsetrue);endLabels.setPullLabel("上拉加载...");}pubivosetResult(LinkedList<JsonBean>list)if(adapter==null)totallist=newLinkedList<JsonBean>();//创建适配dpe=newChanYouJiAdapter(totallist, gvadapterplgv.setEmptyView(tvemy}{ifDlg{}else//如果是刷新,则清空原来的,加载的}adapter} }}layout/activitypulltorefreshexpandable<xmversion="1.0"encoding="utf-<RelativeLayoutxmlns:android="http://s /apk/res/androidm"/ /apk/res-auto"android:layoutwidth="matcheandroid:layoutheight="match"ohdkulolbryPTeExpnbsndrd"prandroid:layoutwidth="matcheandroid:layoutheight="matchepie"eptr:ptrDrawable="@mipmap/icnrter3pHeTt"FptptitEtaEled"tt:tde"otflnDptr:ptrScrollingWhileRefreshingEnabled="true <!-ptr是pullToRefresh的配置属 使用是需要添 xmlns:ptr="http:// /apk/res-好

ptr:ptrDrawable=“” 上拉下拉图rrme 图标动画取值:flip:翻转rotateprpdrcrud 上拉下拉时头部的背景色rrereC" 上拉下拉时文字颜ptrRefreshableViewBackground设置整个mPullRefreshListView的背景ptSrolngWhieRefrshngnabed刷新的时候,是否允许LstVi或rVew滚动。觉得为true比prLsiewExtrasEnable 决定了Header,Footer以何种方式加入mPullRefreshListView,true为View方式加入,就是滚动时刷新头部 起滚动prpMe=?可选值为:disabled(禁用下拉刷新),rSr(仅支持下拉刷新),plFomn(支持上拉刷新),both(二者都支持manualOnly(只允许手动触发当然了,如果你不喜欢在布局文件中指定,完全可以使用代码设--

在onCreate里面写 lv.setMode(Mode.BOTH);//设置你需要的模android:id="@+id/tvandroid:layoutwidth="wrapnandroid:layoutheight="wrapontenandroid:layoutcenterInParent="true"adiext="暂无数据"android:textSize="20sp"tlayout/pulltorefreshparent<xmversion="1.0"encoding="utf-<RelativeLayoutxmlns:android="http://s /apk/res/androidandroid:layoutwidth="matchprenandroid:layoutheight="matchanidpddg"girid"/android:layoutwidth="35dpandroid:layoutheight="35dpandroid:layoutcenterVertical="true"android:layoutmarginLeft="20dp"android:src="@drawable/access"/>ienrdd"d/pandroid:layoutwidth="wraponeandroid:layoutheight="wrapontenandroid:layoutcenterVertical="true"android:layoutmarginLeft="7dp"android:layouttoRightOf="@id/pimg"nitt"ssandroid:textStyle="bold"tlayout/pulltorefreshchildren<xmversion="1.0"encoding="utf-<RelativeLayoutxmlns:android="http://s /apk/res/androidandroid:layoutwidth="matchprenandroid:layoutheight="wrapt"ieddd"d/candroid:layoutwidh="mtaandroid:layoutheight="40dpandroid:layoutcenterInParent="trueandidgvynteadiext="功能android:textStyle="bold"tpliclassMyPullToRefreshExpandableListAdapterxendBaseExpandableListAdapte{piaList<String>etl=ritMap<String,List<String>>map=pubiMyPullToRefreshExpandableListAdapter(List<String>parentlist,Map<String,s<Srn>pthis.parentlist=aths.=}ubintgetGroupCount({turparentlist.size()}pubintgetChildrenCount(intgroupPosition{rtunmap.get(parentlist.get(groupPosition)).size()}ubOegetGroup(intgroupPosition{eurparentlist.get(groupPosition)}pubObjegetChild(intgroupPosition,inttn{urmap.get(parentlist.get(groupPosition)).get(childPosition)}ublogetGroupId(intgroupPosition{eurgroupPosition}ublgetChildId(intgroupPosition,intchildPosition{rtrchildPosition}//在调用nvadaeiew()时,ListView会刷新显示内容//如果内容的id是有效的,系统会跟据id来确定当前显示哪条内容,也就 VisibleChild的位置//id是否有效通过hasStableIds()确定@pubibooleanhs{etre}@pliVigetGroupView(intgroupPosition,booleanisExpanded,ieconvertViewiwrretParentViewHolderparentViewHolder;if(cnvertie==null)convertVie =LayoutInflater.from(parent.getContext()).inflate(R.layout.pulltorereshparentem,parentViewHolder=nerentViewHolder(convertView);cetet(relr}lparentViewHolder=(ParentViewHolder)conergtag(}tintitle=penstgegrouposition);eervt(tif"s"qsl)enepIe(raelif".ul(lenepI(ree)esif("InfoPath".equals(title)rnepIe(rfa)esif("Lync".equals(title)rnepIe(ry)esif("OneNote".equals(title)nVeHeeawaeoeesif("Outlook".equals(title))rnepIe(resif("".equals(title))parentViewHolder.pimg.setImageResource(R.drawable.esif("Project".equals(title)prVwoepou(lpcesif("Publisher".equals(title)rnepIe(rs)esif("Viso".equals(title)prVwoepou(lvso)esif("Word".equals(title)nVeHeeawaewor)esif("Office".equals(title)

prVwoepou(loeparentViewHolder.pimg.setImageResource(R.mipmap.icaceernte}pubiewgetChildView(intgroupPosition,intchildPosition,boeaisLstChild,iewereViwGoparent)ChildViewHolderleeicortiul)covrLyunafropareCnx().nf(.aoturshhildritem,null)childViewHolder=neChildViewolder(convertView)onrtghdire

childViewHolder=(ChildViewHolder)etewe}leor.e(tentrPoi(hPerovi}pubbooleanisChildSelectable(intgroupPosition,nidPoin{uru}classParentViewHoldermageViemtViptv;ubcParentViewHolder(Viewvi)t.m=(ImageViwvewinViewyId(R.id.pimg)p ete view.findViewById(R.id.ptv)}}classChildViewHolderTtVpliChildViewHolder(Viewewtt Ti e.ieidc}}}ubcclassPullToRefreshExpandableListViewActivityn tivitypiaPullToRefreshExpandableListViewtrelpvatTextViewtvtypiaList<String>arl =null;piaMap<String,List<String>>map=null;piaExpandableListViewlistView;pvtString[]titles="Access","xce,"InfoPath","Lync""OneNote",Ouook""","Project""Publisher","Viso","Word","Office"pvatString[][]am=newString[][]{{"轻量","桌面数据","SQL支持","图形查询{"表格编辑","表格排版","表格处理","表格打印{"文档编辑","文档排版","文档处理","文档打印{"表单","制作表单","表单工具","桌面客户端{"位置服务","即时动态","语音邮件","即时通信{"用户协作","便笺","信息归档", 沟通{"收发邮件","管理邮箱","登录登出", 绑定{"项目计划","成本控制","图","轻松协作{"应用","元素控制","页面布局","高端商务{"可视化处理","图表控制","业务决策","专业外观图表"},{"演示编辑","演示排版","演示处理","演示打印{"办公","OLE数据","开档","套装eevionCreate(Bundle{activit db lsvr=(PullToRefreshExpandableListView)ptrelvtvpt=(TextView)findiBdR.dtvpylie =ptefinalMyPullToRefreshExpandableListAdapteradapter=newrparentlit,apliwlitVi.setEmptyView(tvemptyplfrLne PullToRefreshBase.OnRefreshListener2<ExpandableListView>()下拉ubcvoonPullDownToRefresh(PullToRefreshBase<ExpandableListView>{paretlist r"List<String>list=newArrayList<String>();"Other1""Other2""Other3""Other4"map"Other",p plete();//通知}上拉ubcvoonPullUpToRefresh(PullToRefreshBase<ExpandableListView>{arentlist"Other"List<String>list=newArrayList<String>();"Other1""Other2""Other3""Other4"map"Other",p plete();//通知}}pvatiinitData()ptl= map=newHashMap<String,for(inti=0;i<ieseghi++)List<String>templist=newprtlisttitlsfor(intj=0;j<armslngthj++)i.arms;}maptitles }}}xmlversion="1.0"encoding="utf-LineaLyouxmlns:android="http:// /apk/res/androidandroid:layoutwidth="matchprenandroid:layoutheight="matchpennrdoinaovr"kullerh.rlTrhrli:id="@+id/ptrscrollview"android:layoutwidth="matchprenandroid:layoutheight=mtpareniieryouandiandroiandroiaandiandroiandroiandroi:layuwidth="matche:layuheight="wrapeoieainet"leLuandroid:layoutwidh="mtaandroid:layoutheight="wrapcotetIgeandroid:layoutwidth="50dpandroid:layoutheight="50dpandroid:layoutalignParentRight="true"icia"er"android:src="@drawable/access"xtiandroid:layoutwidh="mtantandroid:layoutheight="50dp"andidgvynteddet"AenrdetSz2android:textStyle="bold"/>lveLyoutxieiandroid:layoutwidh="mtantandroid:layoutheight="matchpan"iei:textSize="20sp"LnrLyutcom.handmark.pulltorefresh.library.PullToRefreshScrollVie LnrLyutpliclassPullToRefreshScrollViewActivityn {PullToRefreshScrollViewptrscrollview;eevionCreate(Bundle{ rolveptslvie=(PullToRefreshScrollView)fVBy(Rdptrslvew//设置加载属性ILoadingLayoutstartLables=ptrscrllviwgoLtytrue,false);startLables.setPullLabel("下拉刷新...");//刚下拉时,显示的提示startLables.setRefreshingLabel("正在刷新...");//刷新startLables.setReleaseLabel("放开刷新..."拉达到距离时//DateUtils.FORMATABBREVALLStringlabel=DateUtils.formatDateTime(this,System.currentTimeMillis(),DateUtils.FORMATSHOWIM|DateUtils.FORMATSHOWDATE|DateUtils.FORMATABBREVALL);ILoadingLayoutendLabels=ptrscrleLryfalsue);prlie.setMode(PullToRefreshBase.Mode.BOTHptrliewtRfrLtnr(ePullToRefreshBase.OnRefreshListener2<ScrollView>()下拉ubcvoonPullDownToRefresh(PullToRefreshBase<ScrollView>{new}上拉ubcvoonPullUpToRefresh(PullToRefreshBase<ScrollView>{new}}ritclGetDataTaskxendAsyn k<Void,Void,LinearLayout>{pece nBackground(Void...params)SystemClock.sleep(2000);//模 个耗时操LinearLayoutlin=tur}rtete inearLayoutlinearLayout)LinearLayoutsubrootlin=(LinearLayout)findViewById(R.id.subrootlin);LinearLayout.LayoutParamsparams=newinarayotayoutaa(inearaoutayotaasMATCHPARENT,LinearLayout.LayoutParams.MATCHPARENTsubrootlin.addView(linearLayout,,// pletewhenthelisthasbeen刷新p i }}//下拉刷新后,动态产生的条布 inearLayoutviewSingleItem()LinearLayoutlayoutrootlin=newLinearLayout(this);layoutrootln.etrnat(LerotVERTICALLinearLayout.LayoutParamsLLLP=newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCHPARENT,LinearLayout.LayoutParams.WRAPCONTENT);//添加第个子布局RelativeLayoutlayoutsubrelative=new//创建个ImageView控ImageViewrelativesubIV=newImageView(this);relativesubIV.setPadding(5,,,5);relativesubstietruerelativesubRelativeLayout.LayoutParamsRLIV=newReltieaut.aotam(50, tALIG RIGHT//把ImageView控件加入到子布局中relativesubIV靠layoutsubrelativelayoutsubrelative.addView(relativesubIV,RL创建个TextViewrelativesu =newthisrelativesu r(ryCENTE);relativesu // relativesu .setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));relativesu.setTextSize(20);RelativeLayout.LayoutParamsRLTV=newelatieat.aotaam(elatieayt.ataasATCHPARENT,50);layoutsubrelative.addView(relativesu,RL//把相对布局加入线性布layoutrootlin.addView(layoutsubrelative,LL加第二个子布TextViewlin =newlin r(ryCENTElin .setText("四月十七,正是去年今日,别君时。忍泪佯低面,含羞半敛眉。"+"不知魂已断,空有梦相随。除却天边月,没人知。linsulayoutrootlin.addView(linsu,LLrtunlayoutroot}}xmlversion="1.0"encoding="utf-LineaLyouxmlns:android="http:// /apk/res/androidm"/ /apk/res-android:layoutwidth="matchpeandroid:layoutheight="matchpennrdoinaovr"mallfellReiandroid:id="@+id/ptrweandroid:layoutwidh="mtantandroid:layoutheight="matchpan"pie"eptr:ptrDrawable="@mipmap/icnrter3pHeTt"FptptitEtaEled"tt:tde"otalecnFEptr:ptrScrollingWhileRefreshingEnabled="true <!-ptr是pullToRefresh的配置属性使用是需要添加 ptr:ptrAnimationStyle=""图标动画取值:flip:翻转rotate旋转ptr:ptrHeaderBackground=""上拉下拉时头部的背景色 上拉下拉时文字颜色 ptristexasbed决定了eader,ootr以何种方式加入uRefshsVew,ue为eadVew方式加入,就是滚动时刷新头部会起滚动。在onCreate里面写:pulllv.setMode(Mode.BOTH);//设置你需要的模式LnrLyutubcclassPullToRefreshWebViewActivityee {piatPullToRefreshWebViewptrwebviewvtWebVieweeweevionCreate(Bundle{activit bveptvi=(PullToRefreshWebView)findViewById(R.id.ptrw//设置加载属性ILoadingLayoutstartLables=ptrebiewLagLuro(talestartLables.setPullLabel("下拉刷新...");//刚下拉时,显示的提示startLables.setRefreshingLabel("正在刷新...");//刷新sarLablesseReleaseLabel(放开刷 下拉达 距离

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论