前段时间从Picasco过度去使用Fresco,过程还是挺享受的,就是中间尝试Ultra-ptr(由于ptr集成lib一直出现问题加之好几年不在维护了)出现了个小问题,查了许多资料没找到,自己摸索找到问题原因了,问题是使用ScrollView上滑到底部然后再下拉,结果拉不下来,ScrollView顶部被隐藏或者说被截掉了。
一开始布局是这么写的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/base_title_layout" />
<in.srain.cube.views.ptr.PtrFrameLayout
android:id="@+id/ptrF"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/simImg1"
style="@style/fresco_SimpleDraweeView_sytle"
android:layout_width="match_parent"
android:layout_height="150dp" />后来改成这样
<?xml version="1.0" encoding="utf-8"?>
<in.srain.cube.views.ptr.PtrFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ptr2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/simImg1"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@color/gray" />就这样,具体原因没去深究。
但是发现,这样仅仅是可以滑动了而已。。。
蛋疼的要死,上滑头部还是会被切掉。。。再次痛苦...
然后就在瞎几把改来改去,发现网上很多demo都可以,开始怀疑自己的代码,于是一行一行看,mmp,人家都是用的
new PtrDefaultHandler(),我用的是new PtrHandler()。
改下,wrnmmp,果然可以了。TT...
突然就想来看下PtrDefaultHandler和PtrHandler到底有什么不同
首先
PtrHandler多了个判断是否可以刷新的方法,
checkCanDoRefresh(PtrFrameLayout frame, View content, View header)注意这个content,这个罪魁祸首,如果使用这个方法的话我们需要重写这个判断是否刷新的方法
一开始我就觉得管他的都可以刷新就直接return true;然后...
后来发现有PtrDefaultHandler()方法后,就知道问题处在checkCanDoRefresh(...)这里。然后重写去判断了@Override public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { ViewGroup viewGroup = (ViewGroup) content; if(viewGroup instanceof ScrollView){ return viewGroup.getScrollY() == 0; }else { return true; } }It's OK!
简单研究了下源码这是PtrDefaultHandler()的源码public static boolean canChildScrollUp(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) .getTop() < absListView.getPaddingTop()); } else { return view.getScrollY() > 0; } } else { return view.canScrollVertically(-1); } }//canChildScrollUp见名知意这,是个判断子View能够上拉的方法,这里返回一个boolean数据public static boolean checkContentCanBePulledDown(PtrFrameLayout frame, View content, View header) { return !canChildScrollUp(content); }这个方法在这里调用,通俗翻译 检查填充物是否被下拉,就是这里判断了ScrollView是否被下拉了,问题的 根源就在这里。
写得可能有点乱,解释可能不太清晰,有疑问欢迎交流哈。
本文介绍了解决ScrollView与PtrFrameLayout在Ultra-ptr库中出现的滑动冲突问题,通过调整Handler实现正常下拉刷新。
919

被折叠的 条评论
为什么被折叠?



