From 8b1aef22b9e147d4dfc54b212dd636d740cec1fe Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Sat, 29 Dec 2012 16:38:23 +0000 Subject: [PATCH] Fix #186 --- .../library/PullToRefreshAdapterViewBase.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/library/src/com/handmark/pulltorefresh/library/PullToRefreshAdapterViewBase.java b/library/src/com/handmark/pulltorefresh/library/PullToRefreshAdapterViewBase.java index 0222515d7..0ff4ebe44 100644 --- a/library/src/com/handmark/pulltorefresh/library/PullToRefreshAdapterViewBase.java +++ b/library/src/com/handmark/pulltorefresh/library/PullToRefreshAdapterViewBase.java @@ -30,6 +30,7 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.FrameLayout; +import android.widget.LinearLayout; import android.widget.ListAdapter; import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; @@ -38,6 +39,22 @@ public abstract class PullToRefreshAdapterViewBase extends PullToRefreshBase implements OnScrollListener { + private static FrameLayout.LayoutParams convertEmptyViewLayoutParams(ViewGroup.LayoutParams lp) { + FrameLayout.LayoutParams newLp = null; + + if (null != lp) { + newLp = new FrameLayout.LayoutParams(lp); + + if (lp instanceof LinearLayout.LayoutParams) { + newLp.gravity = ((LinearLayout.LayoutParams) lp).gravity; + } else { + newLp.gravity = Gravity.CENTER; + } + } + + return newLp; + } + private int mSavedLastVisibleIndex = -1; private OnScrollListener mOnScrollListener; private OnLastItemVisibleListener mOnLastItemVisibleListener; @@ -172,7 +189,9 @@ public final void setEmptyView(View newEmptyView) { ((ViewGroup) newEmptyViewParent).removeView(newEmptyView); } - refreshableViewWrapper.addView(newEmptyView); + // We need to convert any LayoutParams so that it works in our + // FrameLayout + refreshableViewWrapper.addView(newEmptyView, convertEmptyViewLayoutParams(newEmptyView.getLayoutParams())); } if (mRefreshableView instanceof EmptyViewMethodAccessor) {