Tuve que hacer esto yo mismo, para mostrar el botón "Acepto" una vez que el usuario se haya desplazado al final de un EULA. Abogados, ¿eh?
De hecho, cuando anula WebView (en lugar de ScrollView como en la respuesta de @JackTurky) puede llamar a getContentHeight() para obtener el alto del contenido, en vez de getBottom() que devuelve el fondo visible y es Inútil.
Esta es mi solución integral. Por lo que puedo ver, esto es todo lo de API Nivel 1, por lo que debería funcionar en cualquier lugar.
public class EulaWebView extends WebView {
public EulaWebView(Context context)
{
this(context, null);
}
public EulaWebView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public EulaWebView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public OnBottomReachedListener mOnBottomReachedListener = null;
private int mMinDistance = 0;
/**
* Set the listener which will be called when the WebView is scrolled to within some
* margin of the bottom.
* @param bottomReachedListener
* @param allowedDifference
*/
public void setOnBottomReachedListener(OnBottomReachedListener bottomReachedListener, int allowedDifference) {
mOnBottomReachedListener = bottomReachedListener;
mMinDistance = allowedDifference;
}
/**
* Implement this interface if you want to be notified when the WebView has scrolled to the bottom.
*/
public interface OnBottomReachedListener {
void onBottomReached(View v);
}
@Override
protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) {
if (mOnBottomReachedListener != null) {
if ((getContentHeight() - (top + getHeight())) <= mMinDistance)
mOnBottomReachedListener.onBottomReached(this);
}
super.onScrollChanged(left, top, oldLeft, oldTop);
}
}
Lo utilizo para mostrar un botón de "Aceptar" una vez que el usuario ha desplazado hasta la parte inferior de la vista Web, donde yo lo llamo así (en una clase que "implementa OnBottomReachedListener":
EulaWebView mEulaContent;
Button mEulaAgreed;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eula);
mEulaContent = (EulaWebView) findViewById(R.id.eula_content);
StaticHelpers.loadWebView(this, mEulaContent, R.raw.stylesheet, StaticHelpers.readRawTextFile(this, R.raw.eula), null);
mEulaContent.setVerticalScrollBarEnabled(true);
mEulaContent.setOnBottomReachedListener(this, 50);
mEulaAgreed = (Button) findViewById(R.id.eula_agreed);
mEulaAgreed.setOnClickListener(this);
mEulaAgreed.setVisibility(View.GONE);
}
@Override
public void onBottomReached(View v) {
mEulaAgreed.setVisibility(View.VISIBLE);
}
Así que cuando se llega a la parte inferior (o en este caso, cuando se hacen dentro de los 50 píxeles de la misma) el botón "Acepto" aparece el botón.
Sin embargo, la vista web no hace referencia al botón. – Daniel