ユーザーがEULAの一番下までスクロールしたときに「同意する」ボタンを表示するには、これを自分で行う必要がありました。弁護士か?
実際、(@JackTurky からの回答のように ScrollView ではなく) WebView をオーバーライドすると、computeVerticalScrollRange() を呼び出してコンテンツの高さを取得できます。
これが私の包括的なソリューションです。私が見る限り、これはすべて 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 ( (computeVerticalScrollRange() - (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 ピクセル以内に到達すると)、「同意する」ボタンが表示されます。