I want to set 'Overscroll' header and 'Overscroll' footer in a scroll view .ScrollView Overscroll is working fine. But i couldn't set header and footer in scroll view. But in scroll view "overScrollHeader" and "overScrollFooter" methods are unavailable.What should i do to set header and footer?
-
I think you have onOverScrolled() and decide from the location if it's the header on footer. – Georgian Benetatos Sep 15 '14 at 11:33
1 Answers
You can not set overScrollHeader/Footer for scrollView. I encountered the same problem, and kept finding listview examples which I cannot use in my case. I figured out a way to do it though. Not sure if its the best way, but basically what I am doing is setting a negative margin on the child of the scrollview. The easiest way to implement it is using the layout xml and simply setting the marginTop to some negative number for the Child ViewGroup of your ScrollView. Then set your bottom padding of your scroll view to the same amount you set to the margin in your child view. (sorry its kind of confusing)
<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.
Whatever is in your ChildView at the very top should show in the overscroll region.
However I didn't want to do it in xml since it's not flexible enough for me I made a custom class where you can set any view you wish to show in the overscroll region.
In your custom scrollview override onMeasure or some other method where you can get the header view's height, and set the child's margin and scrollview's padding dynamically.
Since I didn't need a footer I haven't tried yet but I'm sure there is a way to work it out using the same type of approach. Again, I'm not too sure if this is the best solution (especially using negative margin and padding is kind of scary, although for linear and relative layouts it should be fine) but it worked for me so thought I'd share it!

- 421
- 2
- 8