Java Code Examples for android.support.v4.widget.NestedScrollView

The following examples show how to use android.support.v4.widget.NestedScrollView. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ClipPathLayout   Source File: ScrollTransitionFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    mLayout = (NestedScrollView) inflater.inflate(R.layout.fragment_scroll_transition, null);
    mImageContainer = mLayout.findViewById(R.id.image_container);
    mBelowView = mLayout.findViewById(R.id.below_image);
    mAboveView = mLayout.findViewById(R.id.above_image);
    mLayout.setOnScrollChangeListener(this);
    mLayout.post(new Runnable() {
        @Override
        public void run() {
            if (mController == null) {
                initController();
            }
        }
    });
    return mLayout;
}
 
Example 2
Source Project: CollapsingRefresh   Source File: RefreshContentWrapper.java    License: Apache License 2.0 6 votes vote down vote up
void attach(NestedScrollView scrollView) {
    //获得原始监听器,用作转发
    Field[] declaredFields = NestedScrollView.class.getDeclaredFields();
    if (declaredFields != null) {
        for (Field field : declaredFields) {
            if (NestedScrollView.OnScrollChangeListener.class.equals(field.getType())) {
                try {
                    field.setAccessible(true);
                    Object listener = field.get(scrollView);
                    if (listener != null && !scrollView.equals(listener)) {
                        mScrollChangeListener = (NestedScrollView.OnScrollChangeListener) listener;
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    scrollView.setOnScrollChangeListener(this);
}
 
Example 3
Source Project: WanAndroid   Source File: FavoritesFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_timeline_page, container, false);
    initViews(view);

    //滑动到底部加载下一页
    nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                loadMore();
            }
        }
    });
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            currentPage = INDEX;
            presenter.getFavoriteArticles(INDEX, true, true);

        }
    });

    return view;
}
 
Example 4
Source Project: JReadHub   Source File: TopicDetailFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initDataAndEvent() {
    mToolbar.setNavigationOnClickListener(v -> pop());
    mToolbar.setOnMenuItemClickListener(this);

    mTimelineAdapter = new TopicTimelineAdapter(getContext());
    mRecyclerTimeline.setAdapter(mTimelineAdapter);
    mRecyclerTimeline.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerTimeline.setNestedScrollingEnabled(false);

    mScrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
        if (scrollY > mTxtTopicTime.getBottom()) {
            mToolbarHeader.setVisibility(View.VISIBLE);
            mToolbar.setTitle("");
        } else {
            mToolbarHeader.setVisibility(View.GONE);
            mToolbar.setTitle(getText(R.string.menu_topic_detail));
        }
    });
}
 
Example 5
Source Project: DanDanPlayForAndroid   Source File: ScrollableHelper.java    License: MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
public void smoothScrollBy(int velocityY, int distance, int duration) {
    View scrollableView = getScrollableView();
    if (scrollableView instanceof AbsListView) {
        AbsListView absListView = (AbsListView) scrollableView;
        if (Build.VERSION.SDK_INT >= 21) {
            absListView.fling(velocityY);
        } else {
            absListView.smoothScrollBy(distance, duration);
        }
    } else if (scrollableView instanceof ScrollView) {
        ((ScrollView) scrollableView).fling(velocityY);
    }  else if (scrollableView instanceof NestedScrollView) {
        ((NestedScrollView) scrollableView).fling(velocityY);
    } else if (scrollableView instanceof RecyclerView) {
        ((RecyclerView) scrollableView).fling(0, velocityY);
    } else if (scrollableView instanceof WebView) {
        ((WebView) scrollableView).flingScroll(0, velocityY);
    }
}
 
Example 6
Source Project: smooth-app-bar-layout   Source File: BaseBehavior.java    License: Apache License 2.0 6 votes vote down vote up
private void initScrollTarget(final CoordinatorLayout coordinatorLayout, final AppBarLayout child) {
  Utils.log("initScrollTarget | %b", vScrollTarget != null);
  if (vScrollTarget != null) {
    long tag = getViewTag(vScrollTarget, true);
    if (!mScrollTargets.contains(tag)) {
      mScrollTargets.add(tag);
      OnScrollListener listener = new OnScrollListener() {

        @Override
        public void onScrollChanged(View view, int x, int y, int dx, int dy, boolean accuracy) {
          if (view == vScrollTarget) {
            BaseBehavior.this.onScrollChanged(coordinatorLayout, child, view, y, dy, accuracy);
          }
        }
      };
      if (vScrollTarget instanceof NestedScrollView) {
        ObservableNestedScrollView.newInstance((NestedScrollView) vScrollTarget, mOverrideOnScrollListener, listener);
      } else if (vScrollTarget instanceof RecyclerView) {
        ObservableRecyclerView.newInstance((RecyclerView) vScrollTarget, listener);
      }
    }
  }
}
 
Example 7
Source Project: qvod   Source File: MovieDetailsPresenter.java    License: MIT License 6 votes vote down vote up
private void initListener() {
    //finish
    getView().toolBar.setNavigationOnClickListener(view -> getView().onBackPressed());
    //
    getView().nsvTitle.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            scrollChangeHeader(scrollY);
        }
    });
    getView().llLoading.setOnReloadListener(v -> {
        if (JUtils.isNetWorkAvilable())
            //onClick
            initData();
    });
    getView().toolBar.setOnMenuItemClickListener(item -> {
        if (item.getItemId() == R.id.actionbar_more) {
            WebViewActivity.startAction(getView(), positionData.getAlt());
        }
        return false;
    });
}
 
Example 8
Source Project: Expert-Android-Programming   Source File: Utils.java    License: MIT License 6 votes vote down vote up
public static boolean syncOffset(SmoothAppBarLayout smoothAppBarLayout, View target, int verticalOffset, View scroll) {
  boolean isSelected = target == scroll;
  if (scroll instanceof NestedScrollView) {
    NestedScrollView nestedScrollView = (NestedScrollView) scroll;
    if (nestedScrollView.getScrollY() < verticalOffset || (!isSelected && isScrollToTop(target))) {
      nestedScrollView.scrollTo(0, verticalOffset);
    }
    if (isSelected && (nestedScrollView.getScrollY() < verticalOffset || verticalOffset == 0)) {
      nestedScrollView.scrollTo(0, 0);
      smoothAppBarLayout.syncOffset(0);
    }
  } else if (scroll instanceof RecyclerView) {
    RecyclerView recyclerView = (RecyclerView) scroll;
    boolean isAccuracy = recyclerView.getLayoutManager().findViewByPosition(ObservableRecyclerView.HEADER_VIEW_POSITION) != null;
    if (isAccuracy && recyclerView.computeVerticalScrollOffset() < verticalOffset) {
      recyclerView.scrollBy(0, verticalOffset - recyclerView.computeVerticalScrollOffset());
    } else if (!isSelected && isScrollToTop(target)) {
      recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
    }
    if (isAccuracy && isSelected && (recyclerView.computeVerticalScrollOffset() < verticalOffset || verticalOffset == 0)) {
      recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
      smoothAppBarLayout.syncOffset(0);
    }
  }
  return true;
}
 
Example 9
Source Project: Expert-Android-Programming   Source File: Utils.java    License: MIT License 6 votes vote down vote up
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
  int currentOffset = 0;
  if (!mDone) {
    if (v instanceof NestedScrollView) {
      currentOffset = v.getScrollY();
    } else if (v instanceof RecyclerView) {
      currentOffset = ((RecyclerView) v).computeVerticalScrollOffset();
    }
    if (currentOffset < mOffset) {
      vTarget.scrollBy(0, mOffset - currentOffset);
    } else {
      vSmoothAppBarLayout.syncOffset(mOffset);
      mDone = true;
    }
  }
}
 
Example 10
Source Project: Expert-Android-Programming   Source File: BaseBehavior.java    License: MIT License 6 votes vote down vote up
private void initScrollTarget(final CoordinatorLayout coordinatorLayout, final AppBarLayout child) {
  Utils.log("initScrollTarget | %b", vScrollTarget != null);
  if (vScrollTarget != null) {
    long tag = getViewTag(vScrollTarget, true);
    if (!mScrollTargets.contains(tag)) {
      mScrollTargets.add(tag);
      OnScrollListener listener = new OnScrollListener() {

        @Override
        public void onScrollChanged(View view, int x, int y, int dx, int dy, boolean accuracy) {
          if (view == vScrollTarget) {
            BaseBehavior.this.onScrollChanged(coordinatorLayout, child, view, y, dy, accuracy);
          }
        }
      };
      if (vScrollTarget instanceof NestedScrollView) {
        ObservableNestedScrollView.newInstance((NestedScrollView) vScrollTarget, mOverrideOnScrollListener, listener);
      } else if (vScrollTarget instanceof RecyclerView) {
        ObservableRecyclerView.newInstance((RecyclerView) vScrollTarget, listener);
      }
    }
  }
}
 
Example 11
Source Project: Nibo   Source File: ScrollAwareFABBehavior.java    License: MIT License 6 votes vote down vote up
/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 12
Source Project: BaoKanAndroid   Source File: PhotoDetailActivity.java    License: MIT License 6 votes vote down vote up
/**
 * 准备UI
 */
private void prepareUI() {
    mViewPager = (ViewPager) findViewById(R.id.vp_photo_detail_viewPager);
    mTopLayout = findViewById(R.id.ll_photo_detail_top_layout);
    mPageTextView = (TextView) findViewById(R.id.tv_photo_detail_page);
    mReportTextView = (TextView) findViewById(R.id.tv_photo_detail_report);
    mProgressBar = (ProgressBar) findViewById(R.id.pb_photo_detail_progressbar);
    mBottomLayout = findViewById(R.id.ll_photo_detail_bottom_layout);
    mCaptionScriollView = (NestedScrollView) findViewById(R.id.nsv_photo_detail_caption_scrollview);
    mCaptionTextView = (TextView) findViewById(R.id.tv_photo_detail_caption);
    mBackButton = (ImageButton) findViewById(R.id.ib_photo_detail_bottom_bar_back);
    mEditButton = (ImageButton) findViewById(R.id.ib_photo_detail_bottom_bar_edit);
    mCommentButton = (ImageButton) findViewById(R.id.ib_photo_detail_bottom_bar_comment);
    mCollectionButton = (ImageButton) findViewById(R.id.ib_photo_detail_bottom_bar_collection);
    mShareButton = (ImageButton) findViewById(R.id.ib_photo_detail_bottom_bar_share);
    mPlnumTextView = (TextView) findViewById(R.id.tv_photo_detail_plnum);

    // 监听点击事件
    mReportTextView.setOnClickListener(this);
    mBackButton.setOnClickListener(this);
    mEditButton.setOnClickListener(this);
    mCommentButton.setOnClickListener(this);
    mCollectionButton.setOnClickListener(this);
    mShareButton.setOnClickListener(this);

}
 
Example 13
Source Project: smooth-app-bar-layout   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean syncOffset(SmoothAppBarLayout smoothAppBarLayout, View target, int verticalOffset, View scroll) {
  boolean isSelected = target == scroll;
  if (scroll instanceof NestedScrollView) {
    NestedScrollView nestedScrollView = (NestedScrollView) scroll;
    if (nestedScrollView.getScrollY() < verticalOffset || (!isSelected && isScrollToTop(target))) {
      nestedScrollView.scrollTo(0, verticalOffset);
    }
    if (isSelected && (nestedScrollView.getScrollY() < verticalOffset || verticalOffset == 0)) {
      nestedScrollView.scrollTo(0, 0);
      smoothAppBarLayout.syncOffset(0);
    }
  } else if (scroll instanceof RecyclerView) {
    RecyclerView recyclerView = (RecyclerView) scroll;
    boolean isAccuracy = recyclerView.getLayoutManager().findViewByPosition(ObservableRecyclerView.HEADER_VIEW_POSITION) != null;
    if (isAccuracy && recyclerView.computeVerticalScrollOffset() < verticalOffset) {
      recyclerView.scrollBy(0, verticalOffset - recyclerView.computeVerticalScrollOffset());
    } else if (!isSelected && isScrollToTop(target)) {
      recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
    }
    if (isAccuracy && isSelected && (recyclerView.computeVerticalScrollOffset() < verticalOffset || verticalOffset == 0)) {
      recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
      smoothAppBarLayout.syncOffset(0);
    }
  }
  return true;
}
 
Example 14
Source Project: GpCollapsingToolbar   Source File: ScrollController.java    License: Apache License 2.0 6 votes vote down vote up
private void calculateDistance(View view, int scrollY, int oldScrollY) {
    if (mAppBarScrollRange == null || mNestedScrollRange == null) {
        return;
    }

    int totalScrollRange = mAppBarScrollRange + mNestedScrollRange;

    if (view instanceof AppBarLayout) {
        mAppBarScrollPosition = Math.abs(-scrollY);
    } else if (view instanceof NestedScrollView) {
        mNestedScrollPosition = view.getScrollY();
    }

    int scrollPosition = mAppBarScrollPosition + mNestedScrollPosition;
    mScrollPositionMultiplier = (double) (scrollPosition / totalScrollRange);
    if (mOnTotalScrollChangeListener != null) {
        mOnTotalScrollChangeListener.onTotalScrollChanged(view, scrollPosition, mOldScrollPosition, totalScrollRange);
    }
    mOldScrollPosition = scrollPosition;
}
 
Example 15
Source Project: GpCollapsingToolbar   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ImageView imageView = (ImageView) findViewById(R.id.image);
    mNestedScroll = (NestedScrollView) findViewById(R.id.nestedScroll);
    mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
    mParallaxView = (ScrollView) findViewById(R.id.parallax);
    mFab = (FloatingActionButton) findViewById(R.id.fab);
    setSupportActionBar(toolbar);

    setupToolbarAndStatusBar();
    Picasso.with(this).load("https://i.ytimg.com/vi/Un5SEJ8MyPc/maxresdefault.jpg")
            .into(imageView);
    mScrollController.onCreate(savedInstanceState);
}
 
Example 16
/**
 * Look into the CoordiantorLayout for the {@link RNBottomSheetBehavior}
 * @param coordinatorLayout with app:layout_behavior= {@link RNBottomSheetBehavior}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                RNBottomSheetBehavior temp = RNBottomSheetBehavior.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 17
@Override
public void receiveCommand(BottomSheetBehaviorView view, int commandType, @Nullable ReadableArray args) {
    switch (commandType) {
      case COMMAND_SET_REQUEST_LAYOUT:
          setRequestLayout(view);
          return;
      case COMMAND_SET_BOTTOM_SHEET_STATE:
          setBottomSheetState(view, args);
          return;
      case COMMAND_ATTACH_NESTED_SCROLL_CHILD:
          int nestedScrollId = args.getInt(0);
          ViewGroup child = (ViewGroup) view.getRootView().findViewById(nestedScrollId);
          if (child != null && child instanceof NestedScrollView) {
              this.attachNestedScrollChild(view, (NestedScrollView) child);
          }
          return;

      default:
          throw new JSApplicationIllegalArgumentException("Invalid Command");
    }
}
 
Example 18
/**
 * BottomSheetBehaviorView inherits a NestedScrollView in order to work
 * with the anchor point, but it breaks any ReactNestedScrollView child,
 * so we are changing the behavior of ReactNestedScrollView to disable
 * the nested scroll of the bottom sheet, and enable when the child scroll
 * reaches the top offset.
 */
private void attachNestedScrollChild(final BottomSheetBehaviorView parent, final NestedScrollView nestedScroll) {
    nestedScroll.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_MOVE) {
                if (nestedScroll.computeVerticalScrollOffset() == 0) {
                    parent.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
                } else {
                    parent.stopNestedScroll();
                }
            }
            return nestedScroll.onTouchEvent(event);
        }
    });
}
 
Example 19
/**
 * Look into the CoordiantorLayout for the {@link RNBottomSheetBehavior}
 * @param coordinatorLayout with app:layout_behavior= {@link RNBottomSheetBehavior}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                RNBottomSheetBehavior temp = RNBottomSheetBehavior.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 20
Source Project: Android-TopScrollHelper   Source File: ScrollingActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrolling);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    mNestedScrollView = (NestedScrollView) findViewById(R.id.scrollView);

    initTopScrollHelper();
}
 
Example 21
Source Project: PullRefreshView   Source File: VCanPullUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static VPullable getPullAble(View view) {
    if (view == null) {
        return null;
    }
    view.setOverScrollMode(View.OVER_SCROLL_NEVER);
    if (view instanceof VPullable) {
        return (VPullable) view;
    } else if (view instanceof AbsListView) {
        return new AbsListViewCanPull((AbsListView) view);
    } else if (view instanceof ScrollView || view instanceof NestedScrollView) {
        return new ScrollViewCanPull((ViewGroup) view);
    } else if (view instanceof WebView) {
        return new WebViewCanPull((WebView) view);
    } else if (view instanceof RecyclerView) {
        return new RecyclerViewCanPull((RecyclerView) view);
    }
    return null;
}
 
Example 22
Source Project: smooth-app-bar-layout   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
  int currentOffset = 0;
  if (!mDone) {
    if (v instanceof NestedScrollView) {
      currentOffset = v.getScrollY();
    } else if (v instanceof RecyclerView) {
      currentOffset = ((RecyclerView) v).computeVerticalScrollOffset();
    }
    if (currentOffset < mOffset) {
      vTarget.scrollBy(0, mOffset - currentOffset);
    } else {
      vSmoothAppBarLayout.syncOffset(mOffset);
      mDone = true;
    }
  }
}
 
Example 23
@Override
public void onStart() {
    super.onStart();
    NestedScrollView mScrollView = getView().findViewById(R.id.nestedScrollView);
    MaterialViewPagerHelper.registerScrollView(getActivity(), mScrollView);
    onFleetChange(null);
    onResChange(null);
}
 
Example 24
Source Project: pe-protector-moe   Source File: LogFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    textViewLog = getView().findViewById(R.id.tv_log);
    NestedScrollView mScrollView = getView().findViewById(R.id.log_NestedScrollView);
    MaterialViewPagerHelper.registerScrollView(getActivity(), mScrollView);
    onResChange(null);
    onAddLog(null);
}
 
Example 25
Source Project: ClipPathLayout   Source File: ScrollTransitionFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollChange(NestedScrollView nestedScrollView, int i, int i1, int i2, int i3) {
    int top = mImageContainer.getTop();
    int height = mImageContainer.getHeight();
    int scrollCenter = i1 + nestedScrollView.getHeight() / 2;
    if (scrollCenter < top && mAbove) {
        mOver = true;
    } else if (scrollCenter > top + height && !mAbove) {
        mOver = true;
    } else {
        mOver = false;
    }
    controlProgress(scrollCenter - top, height);
}
 
Example 26
Source Project: WanAndroid   Source File: ArticlesFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_timeline_page, container, false);
    initViews(view);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.e("Custom", "onRefresh: " );
            currentPage = INDEX;
            presenter.getArticles(INDEX,true,true);
        }
    });

    //滑动到底部加载下一页
    nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                loadMore();
            }
        }
    });



    return view;
}
 
Example 27
Source Project: DanDanPlayForAndroid   Source File: ScrollableHelper.java    License: MIT License 5 votes vote down vote up
private static boolean isNestedScrollViewTop(NestedScrollView nestedScrollView) {
    if (nestedScrollView != null) {
        int scrollViewY = nestedScrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 28
@Override
public void onBackPressed() {
    if (mWebView.canGoBack()){
        mWebView.goBack();
    } else {
        NestedScrollView parent = (NestedScrollView) mWebView.getParent();
        if (null != parent) {
            parent.removeAllViews();
        }
        mWebView.destroy();
        super.onBackPressed();
    }
}
 
Example 29
Source Project: Sofia   Source File: CommonActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_common);

    mToolbar = findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view);
    mHeaderView = findViewById(R.id.header);

    final int startColor = ContextCompat.getColor(this, R.color.colorPrimary);
    final int endColor = ContextCompat.getColor(this, R.color.colorNavigation);

    nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            int headerHeight = mHeaderView.getHeight();
            int scrollDistance = Math.min(scrollY, headerHeight);
            float fraction = (float) scrollDistance / (float) headerHeight;

            setToolbarStatusBarAlpha(evaluate(fraction, startColor, endColor));
            setNavigationViewColor(evaluate(fraction, endColor, startColor));
        }
    });

    Sofia.with(this)
            .statusBarBackground(ContextCompat.getColor(this, R.color.colorPrimary))
            .navigationBarBackground(ContextCompat.getDrawable(this, R.color.colorNavigation));
}
 
Example 30
@Override
public void addView(CoordinatorLayoutView parent, View child, int index) {
    super.addView(parent, child, index);
    if (child instanceof NestedScrollView) {
        CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        );

        params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
        child.setLayoutParams(params);
    }
}