SmartRefreshLayout源码分析

来源:互联网 发布:nginx java应用 编辑:程序博客网 时间:2024/05/22 12:21

先看看基本功能:BasicUsingActivity

布局文件:

<com.scwang.smartrefresh.layout.SmartRefreshLayout    android:id="@+id/refreshLayout"    android:layout_width="match_parent"    android:layout_height="match_parent">    <ListView        android:id="@+id/listview"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="@android:color/white"        tools:listitem="@android:layout/simple_list_item_2"/>    <com.scwang.smartrefresh.layout.footer.ClassicsFooter        android:layout_width="match_parent"        android:layout_height="wrap_content"        app:srlClassicsSpinnerStyle="Translate"/></com.scwang.smartrefresh.layout.SmartRefreshLayout>

默认的hearder是

ClassicsHeader

static {    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);    SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {        @NonNull        @Override        public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {            layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//全局设置主题颜色            return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);        }    });}

listview 要包裹一层

mRefreshContent = new RefreshContentWrapper(view);

把listview放在最前边:

bringChildToFront(mRefreshContent.getView());


先了解一下NestedScrollingParent

http://blog.csdn.net/lmj623565791/article/details/52204039

https://github.com/hongyangAndroid/Android-StickyNavLayout

public void onNestedPreScroll(View target, int dx, int dy, int[] consumed){   // Log.e(TAG, "onNestedPreScroll");    Log.d(TAG, "dx = [" + dx + "], dy = [" + dy + "], consumed = [" + consumed + "]");    boolean hiddenTop = dy > 0 && getScrollY() < mTopViewHeight; //向上滑动    boolean showTop = dy < 0 && getScrollY() >= 0 && !ViewCompat.canScrollVertically(target, -1); //向下滑动 ,recyclerview如果不能向下滑动,就会展示top    if (hiddenTop || showTop)    {        scrollBy(0, dy);        consumed[1] = dy;    }}

@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){    //不限制顶部的高度    Log.d(TAG, "onMeasure: ");    super.onMeasure(widthMeasureSpec, heightMeasureSpec);    getChildAt(0).measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));    ViewGroup.LayoutParams params = mViewPager.getLayoutParams();    params.height = getMeasuredHeight() - mNav.getMeasuredHeight();    //mViewPager.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(params.height,MeasureSpec.EXACTLY));//我自己加的
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);//我自己加的,和上边一行的二选一
setMeasuredDimension(getMeasuredWidth(), mTop.getMeasuredHeight() + mNav.getMeasuredHeight() + mViewPager.getMeasuredHeight());}

https://github.com/race604/FlyRefresh

树干是用path 实现的,画的是轮廓。




原创粉丝点击