Fala Tiago,
You will need to create an interface class:
public interface ScrollViewListener {
void onScrollChanged(ScrollViewExt scrollView,
int x, int y, int oldx, int oldy);
}
Once done, 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 will need to change 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 that way in Java, and daclara a Istener:
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 tricky, but it’s the solution to use it on a fragment.
Hugs.
I already do a extends Fragment, as I do to give another extend?
– Tiago Taraczuk
Speak James, I forgot this detail, sorry, I edited my answer, give a look how to do there.
– Leonardo Dias