Scroll to Collapse view without toolbar

I am making a layout similar to the recent Android status bar.

enter image description here

I have two containers Views. ViewPagerand RecyclerView. The default behavior should be that when I scroll RecyclerView, I want it to ViewPagerdecrease in size and vice versa.

enter image description here

Logic:

viewPagerMaxHeight = 200;
if scrollTop
  is ViewPager.height > viewPagerMaxHeight?
    YES: Prevent Scroll and Decrease ViewPager size apropriatry
    No: Scroll RecyclerView
if scrollBottom
  did we scroll to position 0?
    YES: Start increasing ViewPager size
    No: Scroll RecyclerView

A few notes:  - RecyclerViewcontains elements of different sizes. - Sometimes elements are deleted and added - This is a simple RecyclerView, and not like in notifications where they collide with each other.

I can build most of the logic myself, but I could not make the right listener for RecyclerView, which will return the direction and amount of scroll. prevention RecyclerViewfrom scrolling is a bonus

EDIT:

github

v.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
        Log.e("scrollY", ""+scrollY);
        Log.e("oldScrollY", ""+oldScrollY);
        Log.e("currentHeight", ""+currentHeight);
        if(scrollY == 200) {
            Log.e("==200", "JU");
        } else if (scrollY < 200) {
            Log.e("<200", ""+currentHeight);

            if(currentHeight < fullHeight) {
                Log.e("current<full", Integer.toString(deltaScroll));
                deltaScroll = oldScrollY - scrollY;
                currentHeight = currentHeight + deltaScroll;
                if(currentHeight > fullHeight) {
                    currentHeight = fullHeight;
                }
                ku.getLayoutParams().height = currentHeight;
                ku.requestLayout();
            }
            v.scrollTo(0, 200);
        } else if (scrollY > oldScrollY) {
            Log.e("Scroll DOWN", "" + Integer.toString(scrollY));
            deltaScroll = scrollY - oldScrollY;
            currentHeight = currentHeight - deltaScroll;
            if(currentHeight > minHeight) {
                ku.getLayoutParams().height = currentHeight;
                ku.requestLayout();
                v.scrollTo(0, 200);

            } else {
                currentHeight = minHeight;
                ku.getLayoutParams().height = minHeight;
                ku.requestLayout();
            }

        }
    }
});

RecycleView NestedScrollView , . TOP, TOP.

, , , , "" ( , ). , , NestedScrollView , , , .

+6
3

ConstraintLayout Guideline. , , , , .

xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <android.support.constraint.Guideline
        android:id="@+id/viewPagerTopGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.1" />


    <android.support.constraint.Guideline
        android:id="@+id/viewPagerBottomGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.5" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/viewPagerBottomGuideline"
        app:layout_constraintTop_toBottomOf="@+id/viewPagerTopGuideline">

    </android.support.v4.view.ViewPager>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/viewPagerBottomGuideline"/>

</android.support.constraint.ConstraintLayout>

NestedScrollView. onscroll

 @BindView(R.id.viewPagerBottomGuideline)
Guideline guideLine;//have Used ButterKnife

ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) guideLine.getLayoutParams();
            params.guidePercent = 0.20f; // 45% // range: 0 <-> 1
            guideLine.setLayoutParams(params);

, .

+2

:

, , , , "" ...

, , onScrollChange , (- , scroll ==> stop ==> scroll ==> stop ==> scroll ==> stop ==>...), / , (if else), . , , , , , .

:

+2

I would suggest you use CoOrdinate Layout as the main layout (root layout.). then all you have to do is set up a behavior like something like the Collapsing Toolbar via Java or coding. I implemented the same, and this link really helped me a lot. Click on the link and try.

( https://github.com/teocci/AndroidGuidenotes/wiki/Handling-Scrolls-with-CoordinatorLayout )

+2
source

All Articles