I have this dynamic text which will change. I need to enable the button of this layout only if the user read all the texts. (scrolled to the bottom). This is working with the method that I have implemented. scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View view, int i, int i1, int i2, int i3) {
if (isTextViewScrolledToBottom(scrollView, mTextViewNotPDF)) {
mAgreeButton.setEnabled(true);
mAgreeButton.setBackground(getResources().getDrawable(R.drawable.button_bg_black_rounded));
} else {
mAgreeButton.setEnabled(false);
mAgreeButton.setBackground(getResources().getDrawable(R.drawable.button_bg_grey_rounded));
}
}
});
private boolean isTextViewScrolledToBottom(ScrollView scrollView, TextView mTextViewNotPDF) {
int scrollViewHeight = scrollView.getHeight();
int textViewHeight = mTextViewNotPDF.getHeight();
int scrollY = scrollView.getScrollY();
return (textViewHeight) <= (scrollY + scrollViewHeight);
}
But when the text is not long enough to enable the scrollView, this method (onScrollChange)will not be called and button is disabled.
I have tested these so far without a success.
Boolean isAct = scrollView.isEnabled(); // will be true no matter it's showing or not.
Boolean isAct1 = scrollView.isFocusable(); // will be true no matter it's showing or not.
Have you tried
scrollView.canScrollVertically(1)(positive value to check scrolling down)?
You'd do this when your view is created (outside of your
onScrollChangebecause it might not get called). But pay attention that the views probably need to be drawn and measured first:If this doesn't work, how about checking whether the textViewHeight is smaller than your scrollView's height? Again making sure that the views are already drawn and measured.