- 浏览: 505591 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (200)
- java基础 (30)
- ajax (19)
- 乱写 (5)
- groovy (2)
- db (8)
- gwt (0)
- jee (2)
- 我关注的开源 (1)
- RIA AIR (1)
- spring (11)
- lucene (0)
- 工具 (10)
- 百科 (2)
- linux (6)
- android (40)
- 移动开发 (21)
- 代码片断 (15)
- tomcat (1)
- css (1)
- html5 (2)
- jquery (2)
- playframework (3)
- web (2)
- nio (3)
- design (1)
- nosql (3)
- 日志 (12)
- mysql (4)
- 图表 (1)
- python (3)
- ruby (1)
- git (0)
- hibernate (1)
- springboot (1)
- guava (1)
- mybatis (0)
- 工作问题 (3)
- php (1)
最新评论
-
linzm1990:
踩了很多坑啊。。。。
hibernate @Nofound 与@ManyToOne fetch lazy的问题 -
Ccccrrrrrr:
...
转: Spring boot 文件上传 -
rmzdb:
兄弟,你这个东西,在ie内核的浏览器,貌似不识别 文件名
工作问题:http下载文件,中文文件名在firefox下乱码问题 -
107x:
问题解决了,谢谢!
工作问题:http下载文件,中文文件名在firefox下乱码问题 -
klxqljq:
额鹅鹅鹅
android布局实现头尾固定, 中间多余内容可以滚动
转自: http://dengyin2000.iteye.com/blog/1187823
android的UI组件,其中就包括了一个android-pulltorefresh组件。
https://github.com/johannilsson/android-pulltorefresh
这个组件是用在twitter微博中的, 往下拉列表的话, 顶部会自动load, 而且有反弹的效果,非常cool。 但是它的自动load顶部的内部, 我现在需要拖拉listview到最后的时候load。这个组件不知道方向的选择, 所以自己就动手改了下,实现从底部load。 (今天发现新浪微博也实现了同样的功能。) 附件是源码。
com.markupartist.android.widget.PullToRefreshListView
android的UI组件,其中就包括了一个android-pulltorefresh组件。
https://github.com/johannilsson/android-pulltorefresh
这个组件是用在twitter微博中的, 往下拉列表的话, 顶部会自动load, 而且有反弹的效果,非常cool。 但是它的自动load顶部的内部, 我现在需要拖拉listview到最后的时候load。这个组件不知道方向的选择, 所以自己就动手改了下,实现从底部load。 (今天发现新浪微博也实现了同样的功能。) 附件是源码。
com.markupartist.android.widget.PullToRefreshListView
package com.markupartist.android.widget; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.widget.*; import android.widget.AbsListView.OnScrollListener; import com.markupartist.android.widget.pulltorefresh.R; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class PullToRefreshListView extends ListView implements OnScrollListener { private static final int TAP_TO_REFRESH = 1; private static final int PULL_TO_REFRESH = 2; private static final int RELEASE_TO_REFRESH = 3; private static final int REFRESHING = 4; private static final String TAG = "PullToRefreshListView"; private OnRefreshListener mOnRefreshListener; /** * Listener that will receive notifications every time the list scrolls. */ private OnScrollListener mOnScrollListener; private LayoutInflater mInflater; private RelativeLayout mRefreshView; private TextView mRefreshViewText; private ImageView mRefreshViewImage; private ProgressBar mRefreshViewProgress; private TextView mRefreshViewLastUpdated; private int mCurrentScrollState; private int mRefreshState; private RotateAnimation mFlipAnimation; private RotateAnimation mReverseFlipAnimation; private int mRefreshViewHeight; private int mRefreshOriginalTopPadding; private int mRefreshOriginalBottomPadding; private int mLastMotionY; public PullToRefreshListView(Context context) { super(context); init(context); } public PullToRefreshListView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public PullToRefreshListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } private void init(Context context) { // Load all of the animations we need in code rather than through XML mFlipAnimation = new RotateAnimation(0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); mFlipAnimation.setInterpolator(new LinearInterpolator()); mFlipAnimation.setDuration(250); mFlipAnimation.setFillAfter(true); mReverseFlipAnimation = new RotateAnimation(-180, 0, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); mReverseFlipAnimation.setInterpolator(new LinearInterpolator()); mReverseFlipAnimation.setDuration(250); mReverseFlipAnimation.setFillAfter(true); mInflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE); mRefreshView = (RelativeLayout) mInflater.inflate( R.layout.pull_to_refresh_header, this, false); mRefreshViewText = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text); mRefreshViewImage = (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image); mRefreshViewProgress = (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress); mRefreshViewLastUpdated = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_updated_at); mRefreshViewImage.setMinimumHeight(50); mRefreshView.setOnClickListener(new OnClickRefreshListener()); mRefreshOriginalTopPadding = mRefreshView.getPaddingTop(); mRefreshOriginalBottomPadding = mRefreshView.getPaddingBottom(); mRefreshState = TAP_TO_REFRESH; // addHeaderView(mRefreshView); addFooterView(mRefreshView); super.setOnScrollListener(this); measureView(mRefreshView); mRefreshViewHeight = mRefreshView.getMeasuredHeight(); } @Override protected void onAttachedToWindow() { //setSelection(1); } @Override public void setAdapter(ListAdapter adapter) { super.setAdapter(adapter); //setSelection(1); } /** * Set the listener that will receive notifications every time the list * scrolls. * * @param l The scroll listener. */ @Override public void setOnScrollListener(OnScrollListener l) { mOnScrollListener = l; } /** * Register a callback to be invoked when this list should be refreshed. * * @param onRefreshListener The callback to run. */ public void setOnRefreshListener(OnRefreshListener onRefreshListener) { mOnRefreshListener = onRefreshListener; } /** * Set a text to represent when the list was last updated. * * @param lastUpdated Last updated at. */ public void setLastUpdated(CharSequence lastUpdated) { if (lastUpdated != null) { mRefreshViewLastUpdated.setVisibility(View.VISIBLE); mRefreshViewLastUpdated.setText(lastUpdated); } else { mRefreshViewLastUpdated.setVisibility(View.GONE); } } @Override public boolean onTouchEvent(MotionEvent event) { final int y = (int) event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_UP: if (!isVerticalScrollBarEnabled()) { setVerticalScrollBarEnabled(true); } if (getLastVisiblePosition() == getAdapter().getCount() - 1 && mRefreshState != REFRESHING) { if (( mRefreshView.getTop() <= getMeasuredHeight() - mRefreshViewHeight) && mRefreshState == RELEASE_TO_REFRESH) { // Initiate the refresh mRefreshState = REFRESHING; prepareForRefresh(); onRefresh(); } else if (mRefreshView.getTop() > getMeasuredHeight() - mRefreshViewHeight) { // Abort refresh and scroll down below the refresh view resetHeader(); //setSelection(1); if (getFooterViewsCount() > 0) { setSelectionFromTop(getAdapter().getCount() - 1, (this.getMeasuredHeight())); } // if (mRefreshState != RELEASE_TO_REFRESH){ // scrollTo(0, mRefreshView.getScrollY() - mRefreshViewHeight); // } } } break; case MotionEvent.ACTION_DOWN: mLastMotionY = y; break; case MotionEvent.ACTION_MOVE: applyHeaderPadding(event); break; } return super.onTouchEvent(event); } private void applyHeaderPadding(MotionEvent ev) { final int historySize = ev.getHistorySize(); // Workaround for getPointerCount() which is unavailable in 1.5 // (it's always 1 in 1.5) int pointerCount = 1; try { Method method = MotionEvent.class.getMethod("getPointerCount"); pointerCount = (Integer) method.invoke(ev); } catch (NoSuchMethodException e) { pointerCount = 1; } catch (IllegalArgumentException e) { throw e; } catch (IllegalAccessException e) { System.err.println("unexpected " + e); } catch (InvocationTargetException e) { System.err.println("unexpected " + e); } // Log.i("PullToRefreshListView", "historySize:" + historySize); // Log.i("PullToRefreshListView", "pointerCount:" + pointerCount); // Log.i("PullToRefreshListView", " "); // Log.i("PullToRefreshListView", " "); // Log.i("PullToRefreshListView", " "); for (int h = 0; h < historySize; h++) { for (int p = 0; p < pointerCount; p++) { if (mRefreshState == RELEASE_TO_REFRESH) { if (isVerticalFadingEdgeEnabled()) { setVerticalScrollBarEnabled(false); } int historicalY = 0; try { // For Android > 2.0 Method method = MotionEvent.class.getMethod( "getHistoricalY", Integer.TYPE, Integer.TYPE); historicalY = ((Float) method.invoke(ev, p, h)).intValue(); } catch (NoSuchMethodException e) { // For Android < 2.0 historicalY = (int) (ev.getHistoricalY(h)); } catch (IllegalArgumentException e) { throw e; } catch (IllegalAccessException e) { System.err.println("unexpected " + e); } catch (InvocationTargetException e) { System.err.println("unexpected " + e); } // Calculate the padding to apply, we divide by 1.7 to // simulate a more resistant effect during pull. int topPadding = (int) (((historicalY + mLastMotionY) + mRefreshViewHeight) / 1.7); mRefreshView.setPadding( mRefreshView.getPaddingLeft(), mRefreshView.getPaddingTop(), mRefreshView.getPaddingRight(), topPadding); } } } } /** * Sets the header padding back to original size. */ private void resetHeaderPadding() { mRefreshView.setPadding( mRefreshView.getPaddingLeft(), mRefreshView.getPaddingTop(), mRefreshView.getPaddingRight(), mRefreshOriginalBottomPadding); } /** * Resets the header to the original state. */ private void resetHeader() { if (mRefreshState != TAP_TO_REFRESH) { mRefreshState = TAP_TO_REFRESH; resetHeaderPadding(); // Set refresh view text to the pull label mRefreshViewText.setText(R.string.pull_to_refresh_tap_label); // Replace refresh drawable with arrow drawable mRefreshViewImage.setImageResource(R.drawable.ic_pulltorefresh_arrow); // Clear the full rotation animation mRefreshViewImage.clearAnimation(); // Hide progress bar and arrow. mRefreshViewImage.setVisibility(View.GONE); mRefreshViewProgress.setVisibility(View.GONE); } } private void measureView(View child) { ViewGroup.LayoutParams p = child.getLayoutParams(); if (p == null) { p = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width); int lpHeight = p.height; int childHeightSpec; if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Log.i("PullToRefreshListView", "firstVisibleItem:" + firstVisibleItem); // Log.i("PullToRefreshListView", "visibleItemCount:" + visibleItemCount); // Log.i("PullToRefreshListView", "totalItemCount:" + totalItemCount); // Log.i("PullToRefreshListView", ""); // Log.i("PullToRefreshListView", ""); // Log.i("PullToRefreshListView", ""); // When the refresh view is completely visible, change the text to say // "Release to refresh..." and flip the arrow drawable. if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING) { if (firstVisibleItem + visibleItemCount == totalItemCount) { mRefreshViewImage.setVisibility(View.VISIBLE); if (( mRefreshView.getTop() <= getMeasuredHeight() - mRefreshViewHeight) && mRefreshState != RELEASE_TO_REFRESH) { mRefreshViewText.setText(R.string.pull_to_refresh_release_label); mRefreshViewImage.clearAnimation(); mRefreshViewImage.startAnimation(mFlipAnimation); mRefreshState = RELEASE_TO_REFRESH; } else if ( mRefreshView.getTop() > getMeasuredHeight() - 20 - mRefreshViewHeight && mRefreshState != PULL_TO_REFRESH) { mRefreshViewText.setText(R.string.pull_to_refresh_pull_label); if (mRefreshState != TAP_TO_REFRESH) { mRefreshViewImage.clearAnimation(); mRefreshViewImage.startAnimation(mReverseFlipAnimation); } mRefreshState = PULL_TO_REFRESH; } } else { mRefreshViewImage.setVisibility(View.GONE); resetHeader(); } } else if (mCurrentScrollState == SCROLL_STATE_FLING && getLastVisiblePosition() >= getAdapter().getCount() -1 && mRefreshState != REFRESHING) { if (getFooterViewsCount() > 0) { setSelectionFromTop(getAdapter().getCount() - 1, (this.getMeasuredHeight())); } } if (mOnScrollListener != null) { mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } } public View getLoadBarView() { return mRefreshView; } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { mCurrentScrollState = scrollState; if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(view, scrollState); } } public void prepareForRefresh() { resetHeaderPadding(); mRefreshViewImage.setVisibility(View.GONE); // We need this hack, otherwise it will keep the previous drawable. mRefreshViewImage.setImageDrawable(null); mRefreshViewProgress.setVisibility(View.VISIBLE); // Set refresh view text to the refreshing label mRefreshViewText.setText(R.string.pull_to_refresh_refreshing_label); mRefreshState = REFRESHING; } public void onRefresh() { Log.d(TAG, "onRefresh"); if (mOnRefreshListener != null) { mOnRefreshListener.onRefresh(); } } /** * Resets the list to a normal state after a refresh. * * @param lastUpdated Last updated at. */ public void onRefreshComplete(CharSequence lastUpdated) { setLastUpdated(lastUpdated); onRefreshComplete(); } /** * Resets the list to a normal state after a refresh. */ public void onRefreshComplete() { Log.d(TAG, "onRefreshComplete"); resetHeader(); // If refresh view is visible when loading completes, scroll down to // the next item. if (mRefreshView.getBottom() > 0) { invalidateViews(); //setSelection(1); } } /** * Invoked when the refresh view is clicked on. This is mainly used when * there's only a few items in the list and it's not possible to drag the * list. */ private class OnClickRefreshListener implements OnClickListener { @Override public void onClick(View v) { if (mRefreshState != REFRESHING) { prepareForRefresh(); onRefresh(); } } } /** * Interface definition for a callback to be invoked when list should be * refreshed. */ public interface OnRefreshListener { /** * Called when the list should be refreshed. * <p/> * A call to {@link com.itaoo.view.PullToRefreshListView #onRefreshComplete()} is * expected to indicate that the refresh has completed. */ public void onRefresh(); } }
- pulltorefresh.zip (59.7 KB)
- 下载次数: 36
发表评论
-
jackson知识点
2014-05-05 14:13 16381. jackson处理boolean类型的注意点 在使用j ... -
ChartDirectorvk如何测试文本的长度跟宽度
2012-11-30 15:53 1133在使用charDirector画图时, 要确定setPlotA ... -
android listview
2012-07-13 17:37 926ListView与Button的共存问题解决, 解决在list ... -
消息系统部署、维护文档 (HornetQ)
2012-03-06 08:31 0hornetq中文参考文档 一、服务器部署 目前消息服务部 ... -
netty与tomcat等nio的比较(取自zhh2009在论坛里的发言)
2012-03-05 23:58 6918源讨论: http://www.iteye.com/topic ... -
LinkedHashmap的构建函数的第三个参数引发的问题
2012-03-02 17:47 3954注意: 这里只有构造函 ... -
展示字符集编码表示
2012-03-02 13:43 1211import java.nio.ByteBuffer; ... -
nginx 预压缩(gzip)静态文件
2012-01-31 10:01 1708转自: http://willko.iteye.com/blo ... -
米聊所采用的一些技术
2012-01-31 09:52 2080nginx upstream fallback 设置 up ... -
演化理解 Android 异步加载图片
2011-11-09 09:55 902LinearLayout 布局,其下放了5个ImageView ... -
android常用颜色
2011-11-07 08:49 1277常用颜色值: 可以完美的颜色比对的网站: http://w ... -
dialog,activity 屏蔽Home键详解
2011-11-03 09:39 0http://www.iteye.com/topic/1116 ... -
android SlidingDrawer example
2011-11-03 09:35 0http://disanji.net/2010/12/16/a ... -
play flash swf file in android with webview
2011-11-03 09:34 0http://androidforums.com/applic ... -
AnimationDrawable 在Dialog中不能动画的原因(转)
2011-11-03 09:33 1302原来在dialog的onCreate onStart调用的时候 ... -
Free Android UI library & component roundup
2011-11-03 09:27 1145http://java.dzone.com/articles/ ... -
Android Fundamentals: Scheduling Recurring Tasks
2011-11-03 09:26 982http://mobile.tutsplus.com/tuto ... -
Android中dp和px之间进行转换
2011-11-03 09:02 2258在xml布局文件中,我们既可以设置px,也可以设置dp(或者d ... -
view的setTag() 和 getTag()应用
2011-10-31 12:19 29932View中的setTag(Onbect)表示给View添加一个 ... -
使用getIdentifier()获取资源Id
2011-10-31 12:15 8457使用getIdentifier()获取资源Id int i ...
相关推荐
实现Pull-to-Refresh的方法有很多,其中一种是使用开源库,如`android-pulltorefresh`。这个库提供了易于集成的解决方案,允许开发者快速添加此功能。`pulltorefresh`目录中的代码可能包含了这个库的部分源码,供...
在Android应用开发中,下拉刷新(Pull-to-Refresh)功能已经成为许多应用的标准配置,它允许用户通过简单地向下拉动列表来更新内容。 Ultra-pull-to-refresh 是一个流行的开源第三方库,专为Android设计,提供了一种...
使用这个库,你可以自定义刷新头部视图,甚至实现上拉加载更多(Pull-up-to-load-more)的功能。 在`PullToRefreshActivity`这个示例文件中,可能包含了使用类似`android-pulltorefresh`库实现的拉动刷新ListView的...
**下拉刷新(Pull-to-Refresh)** 下拉刷新功能允许用户通过在ListView顶部向下拉动来获取最新的数据。这在实时性要求较高的应用中尤其有用。实现下拉刷新一般包括以下步骤: 1. **集成下拉刷新库**:Android提供了...
一、下拉刷新(Pull to Refresh) 下拉刷新通常用于更新列表的最新数据。实现这一功能可以借助SwipeRefreshLayout库,它提供了一个可滑动刷新的容器,包括ListView、GridView等。以下步骤可以帮助你实现这个功能: ...
This project aims to provide a reusable Pull to Refresh widget for Android. It was originally based on Johan Nilsson's library (mainly for graphics, strings and animations), but these have been ...
2. 自定义刷新提示:使用`PullToRefreshBase.setMode()`方法选择下拉刷新模式,如仅上拉刷新(MODE_PULL_DOWN_TO_REFRESH)、仅下拉刷新(MODE_PULL_UP_TO_REFRESH)或两者都支持(MODE_BOTH)。 3. 提供动画效果:...
* @description An ListView support (a) Pull down to refresh, (b) Pull up to load more. * Implement IXListViewListener, and see stopRefresh() / stopLoadMore(). */ package ...
a widget provided to the flutter scroll component drop-down refresh and pull up load.support android and ios. If you are Chinese,click here(中文文档) (Suspend maintenance until 12 months after the end...
然而,为了提供更好的用户体验,开发者经常需要在ListView中添加上拉加载(Load More)和下拉刷新(Pull to Refresh)的功能。本篇文章将详细讲解如何通过自定义ListView布局来实现这一功能。 首先,我们创建一个名...
} else if (currentStatus == STATUS_PULL_TO_REFRESH) { // 松手时如果是下拉状态,就去调用隐藏下拉头的任务 new HideHeaderTask().execute(); } break; } // 时刻记得更新下拉头中的...
android:text="@string/pull_to_refresh" /> android:id="@+id/updated_at" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center_...
4. **下拉刷新(Pull-to-Refresh)**:ListView的一个流行特性是下拉刷新,用户上滑列表到顶部时,可以触发刷新数据的操作,常用于更新网络数据。 5. **上拉加载(More)**:与下拉刷新类似,上拉加载允许用户在滑动到...
其次,下拉刷新(Pull-to-Refresh)功能允许用户通过在列表顶部下拉来刷新数据。这种功能在新闻应用、社交媒体应用等中非常常见。Android中实现这一功能,可以使用SwipeRefreshLayout组件。设置SwipeRefreshLayout...
在Android应用开发中,下拉刷新(Pull-to-Refresh)是一种常见的交互模式,用户通过下拉列表或视图来触发数据的更新。本项目“Android项目仿新浪微博下拉刷新继承FrameLayout”旨在实现一个类似新浪微博的下拉刷新...
在众多Android应用开发中,下拉刷新(Pull-to-Refresh)功能是提升用户体验的重要手段之一。LearnPullToRefreshControls是一个专门研究和实现这一功能的开源项目,它为我们提供了深入理解下拉刷新机制及其在Android...
### 下拉刷新(Pull-to-Refresh) 下拉刷新是一种用户界面设计模式,当用户在列表顶部向下滑动时,可以触发刷新操作。在Android中,Google提供了`SwipeRefreshLayout`组件来实现这一功能。`SwipeRefreshLayout`包含...