How can we set the scroll header and footer in the scrollview?

I want to set Overscroll Header and Overscroll Footer in Scroll .ScrollView Overscroll works fine. But I could not set the header and footer in scroll mode. But in scrolling mode the "overScrollHeader" and "overScrollFooter" methods are not available. What should I do to set the header and footer?

+3


source to share


1 answer


You cannot set overScrollHeader / Footer on scrollView. I ran into the same problem and kept finding list examples that I cannot use in my case. I figured out how to do it. Not sure if this is the best way, but basically what I am doing is to set negative margin for the scrollview child. The easiest way to implement it is to use the xml layout and just set the marginTop to some negative number for your ScrollView's Child ViewGroup. Then set the bottom padding of your scroll view to the same amount you set in your child view box. (sorry to confuse this)

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:paddingBottom="-100dp">
<LinearLayout
    android:orientation="vertical"
    android:layout_marginTop="-100dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
... etc

      

Something like that.

Anything at the very top of your ChildView should appear in the overscroll area.



However, I didn't want to do this in the xml as it was not flexible enough for me. I created my own class where you can set any view you want to show in the overscroll scope.

In your custom scrollview, override onMeasure or some other method where you can get the header view height and dynamically add a child field and scroll view.

Since I don't need a footer, I haven't tried it yet, but I'm sure there is a way to work it out using the same approach. Again, I'm not too sure if this is the best solution (especially using negative margin and padding - it's scary, although it should be fine for linear and relative layouts), but it worked for me, so I thought I'd share it!

0


source







All Articles