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
- PullToRefresh 使用说明
- pulltorefresh
- PullToRefresh
- PullToRefresh
- PullToRefresh
- PullToRefresh
- PullToRefresh
- pullToRefresh
- PullToRefresh
- PullToRefresh
- pullToRefresh
- pulltorefresh
- Pulltorefresh
- PullToRefresh
- Pulltorefresh
- PullToRefresh
- pullToRefresh
- pulltorefresh
- 怎样练习10000小时
- C++引用传递和值传递
- 双击返回键两次后退出
- HTML中input type="text"和type="password" 显示的长度不一样
- VC通用控件编程之CImageList控件
- PullToRefresh 使用说明
- Swift 构造过程+析构过程(十三)
- 768 移位密码
- android 使用Webview时候清楚缓存各种方式无效后
- PHP 开启报错提示
- 查找没有commit的事务
- 管理员克隆gitolite-admin时提示“ERROR:gitosis.app:Configuration does not exist”错误
- 使用Lucene-Spatial实现集成地理位置的全文检索
- OpenGLES demo - 3. 建立Android工程