Java Code Examples for android.support.v7.widget.RecyclerView#getTop()

The following examples show how to use android.support.v7.widget.RecyclerView#getTop() . 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 File: DividerItemDecoration.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getTop();
    final int bottom = parent.getBottom();

    final Drawable mDivider = this.getDividerManager().getDivider();
    final int childCount = parent.getChildCount();
    View child ;
    RecyclerView.LayoutParams params ;
    int left, right;

    for (int i = 0; i < childCount; i++) {
        child = parent.getChildAt(i);
        params = (RecyclerView.LayoutParams) child.getLayoutParams();
        //分割线的left,right
        left = child.getRight() + params.rightMargin;
        right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 2
Source File: RecyclerViewBehavior.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
    public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, RecyclerView child,
                                  View target, int dx, int dy, int[] consumed) {
//        Log.e("ldf", "onNestedPreScroll");
        super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
        child.setVerticalScrollBarEnabled(true);

        MonthPager monthPager = (MonthPager) coordinatorLayout.getChildAt(0);
        if (monthPager.getPageScrollState() != ViewPager.SCROLL_STATE_IDLE) {
            consumed[1] = dy;
            Log.w("ldf", "onNestedPreScroll: MonthPager dragging");
            Toast.makeText(context, "loading month data", Toast.LENGTH_SHORT).show();
            return;
        }

        // 上滑,正在隐藏顶部的日历
        hidingTop = dy > 0 && child.getTop() <= initOffset
                && child.getTop() > getMonthPager(coordinatorLayout).getCellHeight();
        // 下滑,正在展示顶部的日历
        showingTop = dy < 0 && !ViewCompat.canScrollVertically(target, -1);

        if (hidingTop || showingTop) {
            consumed[1] = Utils.scroll(child, dy,
                    getMonthPager(coordinatorLayout).getCellHeight(),
                    getMonthPager(coordinatorLayout).getViewHeight());
            saveTop(child.getTop());
        }
    }
 
Example 3
Source File: ViewUtils.java    From MultiView with Apache License 2.0 5 votes vote down vote up
public static View getFirstIntersectsChild(RecyclerView recyclerView) {
    int childCount = recyclerView.getChildCount();
    if (childCount > 0) {
        for (int i = 0; i < childCount; i++) {
            View child = recyclerView.getChildAt(i);
            Rect rect1=new Rect(recyclerView.getLeft(),recyclerView.getTop(), recyclerView.getRight(), recyclerView.getBottom());
            Rect rect2=new Rect(child.getLeft(),child.getTop(), child.getRight(), child.getBottom());
            if (Rect.intersects(rect1, rect2)) {
                return child;
            }
        }
    }
    return null;
}
 
Example 4
Source File: ParallaxViewController.java    From BeautifulParallax with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (recyclerView.getChildCount() > 0) {
        if (firstVisibleView == null) firstVisibleView = recyclerView.getChildAt(0);
        if (recyclerviewCenterY == -1) recyclerviewCenterY = recyclerView.getMeasuredHeight() / 2 + recyclerView.getTop();

        for (int i = 0, count = imageViewList.size(); i < count; ++i) {
            currentImageView = imageViewList.get(i);
            currentImageView.getGlobalVisibleRect(rect);

            float yOffset = limit(-1, (recyclerviewCenterY - rect.top) / currentImageView.getHeight(), 1);
            ViewHelper.setTranslationY(currentImageView,(-1f + yOffset) * PARALLAX_SPEED);
        }
    }
}