Speak James,
You will need to create an interface class:
public interface ScrollViewListener {
void onScrollChanged(ScrollViewExt scrollView,
int x, int y, int oldx, int oldy);
}
Once you've done this, you'll need to create a ScrollView class:
public class ScrollViewExt extends ScrollView {
private ScrollViewListener scrollViewListener = null;
public ScrollViewExt(Context context) {
super(context);
}
public ScrollViewExt(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollViewExt(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollViewListener(ScrollViewListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
}
There in your layout, you need to change the scrollView:
<br.com.seupackage.ScrollViewExt
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
</br.com.seupackage.ScrollViewExt>
You declare it this way in Java, and assign a listener:
ScrollViewExt scroll = (ScrollViewExt) findViewById(R.id.id_scroll);
scroll.setScrollViewListener(this);
And finally, you can use the onScrollChange method:
@Override
public void onScrollChanged(ScrollViewExt scrollView, int x, int y, int oldx, int oldy) {
View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
if (diff <= 10) {
// Se o diff for menor que 10, exibe o botão
}
}
It's a little painful, but it's the solution to using it in a Fragment.
Hugs.