Я должен был сделать это сам, чтобы отобразить кнопку «Я согласен», как только пользователь прокрутил нижнюю часть EULA. Адвокаты, да?
Фактически, когда вы переопределяете WebView (а не ScrollView, как в ответе от @JackTurky), вы можете вызвать getContentHeight(), чтобы получить высоту содержимого, а не getBottom(), который возвращает видимое нижнее и не полезно.
Это мое комплексное решение. Насколько я вижу, это все API уровня 1, поэтому он должен работать где угодно.
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);
}
}
Я использую это, чтобы отобразить кнопку «Я согласен», когда пользователь прокрутил в нижней части WebView, где я называю это так (в классе, который «реализует 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);
}
Итак, когда дно достигнуто (или в данном случае, когда они попадают в 50 пикселей It) «Я согласен» появится кнопка.
Веб-просмотр не содержит ссылок на кнопку. – Daniel