PullToRefresh 使用说明

来源:互联网 发布:windows下的linux终端 编辑:程序博客网 时间:2024/06/01 10:35

0,可以配置的参数

 加上这个空间说明: xmlns:ptr="http://schemas.android.com/apk/res-auto"
<?xml version="1.0" encoding="utf-8"?><resources>    <declare-styleable name="PullToRefresh">        <!-- A drawable to use as the background of the Refreshable View -->        <attr name="ptrRefreshableViewBackground" format="reference|color" />        <!-- A drawable to use as the background of the Header and Footer Loading Views -->        <attr name="ptrHeaderBackground" format="reference|color" />        <!-- Text Color of the Header and Footer Loading Views -->        <attr name="ptrHeaderTextColor" format="reference|color" />        <!-- Text Color of the Header and Footer Loading Views Sub Header -->        <attr name="ptrHeaderSubTextColor" format="reference|color" />        <!-- Mode of Pull-to-Refresh that should be used -->        <attr name="ptrMode">            <flag name="disabled" value="0x0" />            <flag name="pullFromStart" value="0x1" />            <flag name="pullFromEnd" value="0x2" />            <flag name="both" value="0x3" />            <flag name="manualOnly" value="0x4" />            <!-- These last two are depreacted -->            <flag name="pullDownFromTop" value="0x1" />            <flag name="pullUpFromBottom" value="0x2" />        </attr>        <!-- Whether the Indicator overlay(s) should be used -->        <attr name="ptrShowIndicator" format="reference|boolean" />        <!-- Drawable to use as Loading Indicator. Changes both Header and Footer. -->        <attr name="ptrDrawable" format="reference" />        <!-- Drawable to use as Loading Indicator in the Header View. Overrides value set in ptrDrawable. -->        <attr name="ptrDrawableStart" format="reference" />        <!-- Drawable to use as Loading Indicator in the Footer View. Overrides value set in ptrDrawable. -->        <attr name="ptrDrawableEnd" format="reference" />        <!-- Whether Android's built-in Over Scroll should be utilised for Pull-to-Refresh. -->        <attr name="ptrOverScroll" format="reference|boolean" />        <!-- Base text color, typeface, size, and style for Header and Footer Loading Views -->        <attr name="ptrHeaderTextAppearance" format="reference" />        <!-- Base text color, typeface, size, and style for Header and Footer Loading Views Sub Header -->        <attr name="ptrSubHeaderTextAppearance" format="reference" />        <!-- Style of Animation should be used displayed when pulling. -->        <attr name="ptrAnimationStyle">            <flag name="rotate" value="0x0" />            <flag name="flip" value="0x1" />        </attr>        <!-- Whether the user can scroll while the View is Refreshing -->        <attr name="ptrScrollingWhileRefreshingEnabled" format="reference|boolean" />        <!--        Whether PullToRefreshListView has it's extras enabled. This allows the user to be         able to scroll while refreshing, and behaves better. It acheives this by adding        Header and/or Footer Views to the ListView.        -->        <attr name="ptrListViewExtrasEnabled" format="reference|boolean" />        <!--        Whether the Drawable should be continually rotated as you pull. This only        takes effect when using the 'Rotate' Animation Style.        -->        <attr name="ptrRotateDrawableWhilePulling" format="reference|boolean" />        <!-- BELOW HERE ARE DEPRECEATED. DO NOT USE. -->        <attr name="ptrAdapterViewBackground" format="reference|color" />        <attr name="ptrDrawableTop" format="reference" />        <attr name="ptrDrawableBottom" format="reference" />    </declare-styleable></resources>



1,XML修改过的

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <!-- The PullToRefreshListView replaces a standard ListView widget. -->    <com.handmark.pulltorefresh.library.PullToRefreshListView        xmlns:ptr="http://schemas.android.com/apk/res-auto"        android:id="@+id/pull_refresh_list"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:cacheColorHint="#00000000"        android:divider="#19000000"        android:dividerHeight="4dp"        android:fadingEdge="none"        android:fastScrollEnabled="false"        android:footerDividersEnabled="false"        android:headerDividersEnabled="false"        android:smoothScrollbar="true"        ptr:ptrMode="both"        ptr:ptrHeaderBackground="#FFFFFF"        ptr:ptrHeaderTextColor="#000000"        ptr:ptrDrawableStart="@drawable/default_indicator_arrow"        ptr:ptrDrawableEnd="@drawable/default_indicator_arrow"        ptr:ptrAnimationStyle="flip"        ptr:ptrRefreshableViewBackground="#FFFFFF" /></LinearLayout>


2,java代码


/******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/package com.handmark.pulltorefresh.samples;import java.util.Arrays;import java.util.LinkedList;import android.app.ListActivity;import android.os.AsyncTask;import android.os.Bundle;import android.text.format.DateUtils;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.TextView;import com.handmark.pulltorefresh.library.PullToRefreshBase;import com.handmark.pulltorefresh.library.PullToRefreshListView;public final class PullToRefreshListActivity extends ListActivity {static final int MENU_MANUAL_REFRESH = 0;static final int MENU_DISABLE_SCROLL = 1;static final int MENU_SET_MODE = 2;static final int MENU_DEMO = 3;private LinkedList<String> mListItems;private PullToRefreshListView mPullRefreshListView;private ArrayAdapter<String> mAdapter;@SuppressWarnings({ "unchecked", "rawtypes" })@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_list);mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);mPullRefreshListView.setOnRefreshListener(new  PullToRefreshBase.OnRefreshListener2() {@Overridepublic void onPullDownToRefresh(PullToRefreshBase refreshView) {String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);new GetDataTask().execute();}@Overridepublic void onPullUpToRefresh(PullToRefreshBase refreshView) {refreshView.post(new Runnable() {@Overridepublic void run() {new LoadMoreDataTask().execute();}});}});mListItems = new LinkedList<String>();mListItems.addAll(Arrays.asList(mStrings));mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems){@Overridepublic View getView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) super.getView(position, convertView, parent);     textView.setTextColor(PullToRefreshListActivity.this.getResources().getColor(android.R.color.black));return textView;}};//mPullRefreshListView.getLoadingLayoutProxy().setLoadingDrawable(//getResources().getDrawable(R.drawable.android));//mPullRefreshListView.getLoadingLayoutProxy().mPullRefreshListView.setAdapter(mAdapter);}private class GetDataTask extends AsyncTask<Void, Void, String[]> {@Overrideprotected String[] doInBackground(Void... params) {try {Thread.sleep(2000);} catch (InterruptedException e) {}return mStrings;}@Overrideprotected void onPostExecute(String[] result) {mListItems.addFirst("Added after refresh...");mAdapter.notifyDataSetChanged();mPullRefreshListView.onRefreshComplete();super.onPostExecute(result);}}private class LoadMoreDataTask extends AsyncTask<Void, Void, String[]> {@Overrideprotected String[] doInBackground(Void... params) {try {Thread.sleep(2000);} catch (InterruptedException e) {}return mStrings;}@Overrideprotected void onPostExecute(String[] result) {mListItems.addLast("Added after Load More...");mAdapter.notifyDataSetChanged();mPullRefreshListView.onRefreshComplete();super.onPostExecute(result);}}private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi","Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre","Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi","Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre","Allgauer Emmentaler" };}

3,项目主体

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.handmark.pulltorefresh.samples"    android:versionCode="2110"    android:versionName="2.1.1" >    <uses-sdk        android:minSdkVersion="11"        android:targetSdkVersion="15" />    <application        android:hardwareAccelerated="true"        android:icon="@drawable/icon"        android:theme="@android:style/Theme.Holo.Light"        android:label="@string/app_name" >        <activity            android:name=".LauncherActivity"            android:label="PullToRefresh Samples" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity            android:name=".PullToRefreshListActivity"            android:label="PtR ListView" >        </activity>        <activity            android:name=".PullToRefreshListFragmentActivity"            android:label="PtR ListView Fragment" >        </activity>        <activity            android:name=".PullToRefreshListInViewPagerActivity"            android:label="PtR ListView in ViewPager" >        </activity>        <activity            android:name=".PullToRefreshGridActivity"            android:label="PtR GridView" >        </activity>        <activity            android:name=".PullToRefreshExpandableListActivity"            android:label="PtR ExpandableListView" >        </activity>        <activity            android:name=".PullToRefreshWebViewActivity"            android:label="PtR WebView" >        </activity>        <activity            android:name=".PullToRefreshScrollViewActivity"            android:label="PtR ScrollView" >        </activity>        <activity            android:name=".PullToRefreshHorizontalScrollViewActivity"            android:label="PtR HorizontalScrollView" >        </activity>        <activity            android:name=".PullToRefreshViewPagerActivity"            android:label="PtR ViewPager" >        </activity>        <activity            android:name=".PullToRefreshWebView2Activity"            android:label="PtR WebView Advanced" >        </activity>    </application>    <!-- For WebView Sample -->    <uses-permission android:name="android.permission.INTERNET" />    <supports-screens android:anyDensity="true" /></manifest>



0 2
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 宝宝只吃母乳不吃奶粉怎么办 十个月宝宝不爱吃辅食怎么办 奶水不足宝宝不吃奶粉怎么办 两个月宝宝不吃奶瓶怎么办 宝宝拉的有鼻涕怎么办 七个月宝宝拉肚子拉水怎么办 十个月宝宝拉肚子拉水怎么办 一个月宝宝拉肚子拉水怎么办 五个月的宝宝拉肚子还拉水怎么办 4岁宝宝拉肚子怎么办拉水样 刚出生的婴儿呕奶怎么办 8岁儿童腹泻呕吐怎么办 一岁宝宝呕吐腹泻怎么办 5岁儿童腹泻呕吐怎么办 4岁宝宝呕吐腹泻怎么办 7岁儿童腹泻呕吐怎么办 一个月婴儿呕奶怎么办 一个月婴儿呕奶严重怎么办 6岁宝宝大便干燥怎么办 3岁儿童干咳嗽怎么办 3岁宝宝一直咳嗽怎么办 3岁宝宝风寒咳嗽怎么办 刚出生的宝宝拉奶瓣怎么办 小孩拉痢疾带血怎么办 2岁宝宝有点拉稀怎么办 1岁宝宝有点拉稀怎么办 3岁宝宝有点拉稀怎么办 甲减粘液性水肿怎么办 五个月宝宝断奶不吃奶粉怎么办 八个半月的宝宝不爱吃饭怎么办 十个半月宝宝不爱吃饭怎么办 九个半月宝宝不爱吃饭怎么办 七个半月宝宝不爱吃饭怎么办 8个半月宝宝不爱吃饭怎么办 八个半月宝宝不爱吃饭怎么办 特百惠杯子摔坏后不给换怎么办 特百惠水杯摔裂了怎么办 焖烧杯摔瘪了怎么办 苦瓜和虾一起吃中毒怎么办 乐扣盖子坏了怎么办 小孩上课坐不住好动怎么办