Skip to content

A library to make views hide from top and bottom while scrolling a custom NestedScrollView

Notifications You must be signed in to change notification settings

naseemakhtar994/ConcealerNestedScrollView

 
 

Repository files navigation

ConcealerNestedScrollView

A library to make views hide from top and bottom while scrolling a custom NestedScrollView.

gif_image

usage

Gradle

implementation 'com.simmorsal.library:concealer_nested_scroll_view:1.0.0'

XML

Starting with your XML layout, it should look like this:

concealernsv-layout-setup

A parent RelativeLayout or FrameLayout that inside it is the ConcealerNestedScrollView on top, and two views (or one) as header and footer below it.

IMPORTANT: DO NOT give margin_top to header view, or margin_bottom to footer view. We'll do that in Java.

Click here to see a XML sample.

JAVA

In your java first get a reference to the ConcealerNestedScrollView widget. (also get a reference to the header and footer views as well).

    ConcealerNestedScrollView cnsv = findViewById(R.id.cnsv);

Then you should pass the headerView and footerView (and margin top for header and margin bottom for footer views) to the cnsv object.

To pass these views, you should make sure that they are completely drawn on the screen, so the library would be able to get their sizes.

In order to do so, in your onCreate call .post() on header and footer views:

    headerView.post(new Runnable() {
        @Override
        public void run() {
            // parameters are (View headerView, int marginTop)
            cnsv.setHeaderView(headerView, 15);
        }
    });
    footerView.post(new Runnable() {
        @Override
        public void run() {
            // parameters are (View footerView, int marginBottom)
            cnsv.setFooterView(footerView, 0);
        }
    });

IMPORTANT NOTES:

  • if you dont want to set header and footer views from inside the onCreate, or you are sure when you want to pass header or footer views, they are drawn on the screen, dont call .post() on the views, and directly pass the views.

  • if on runtime your headerView height size changes (either by directly changing it's size, or setting a view inside it to VISIBLE that causes the view's height size to change), make sure to call cnsv.resetHeaderHeight(); immediately after the code for resizing has been run. Likewise for the footerView, call cnsv.resetFooterHeight();.

  • You can make the views hide twice as fast if the cnsv has been scrolled more than the view's heights, by calling cnsv.setHeaderFastHide(true); and/or cnsv.setFooterFastHide(true);.

Donations

My bitcoin address: 15NkTxJMdZinU2rUnENfjt62uHtxXCcpEU

btc_address

License

Copyright 2018 Soheil Mohammad Hosseini

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

A library to make views hide from top and bottom while scrolling a custom NestedScrollView

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%