I have a WebView
and a native custom view I want to add underneath the WebView
. I've tried wrapping the WebView
inside a ScrollView
, and while that does exactly what i want, the scrolling performance is really laggy and if a user flings the scroll tapping the screen does not stop the fling like it should.
The other approach I was thinking was to inflate the WebView
into a wrapper FrameLayout
with my footer view on top of the WebView
, then somehow extend the WebView
height to accomodate the footer size, push the footer view to the end of the WebView
s height and then monitor the scroll of the WebView
to move the footer with it.
I've setup the base class, my problem is extending the scrollable content in the WebView
, and then pushing the footer to the bottom of the WebView
s content; the main issue being that WebView
isn't your typical android view and the page content load asynchronously (and thus the content size changes).
How can I extend the scrollable content of a WebView
? And how can I set the native footer below the WebView
content?
EDIT:
I don't actually use xml, the view is constructed in code like so:
public class WebViewWithFooter extends FrameLayout {
private ObservableWebView mWebView;//webview with scroll methods overridden for access
private FrameLayout mFooterContainer;
public WebViewWithFooter(Context context) {
super(context);
init();
}
public WebViewWithFooter(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public WebViewWithFooter(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public WebViewWithFooter(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
FrameLayout.LayoutParams footerParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
FrameLayout.LayoutParams webviewParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
mWebView = new ObservableWebView(getContext());
mFooterContainer = new FrameLayout(getContext());
addView(mWebView, webviewParams);
addView(mFooterContainer, footerParams);
}
}
If I've understood you right, you are trying to show/hide the footer when the
WebView
is scrolled, right? If so, I don't think you need a third party library to achieve this. You can extend theWebView
and override the methodonScrollChanged()
. It is called when the horizontal or vertical scroll are changing. If the vertical scroll has changed and it is positive, show the footer, otherwise - hide it.Another idea: have you tried the new design library shipped by Google? There is a convenient way to achieve such behavior for
ListView
orRecyclerView
.Wrap a simple
Webview
, with a footer (LinearLayout
,RelativeLayout
, etc) inside anObservableScrollView
, rather than anObservableWebView
. I cannot go into details as you haven't added any layout files.EDIT:
Activity.xml:
Activity.java:
I achieved this using layout xml code as follows:
Below the blue text there is a scrollable Webview, and a button footer. Is this valid for you?
Correct me if I'm wrong, but basically you want to have your footer view at the bottom of the page and your webview take up all of the space that's left?
Why don't you just put your footer view inside a RelativeLayout with the alignParentBottom set to true, then have your WebView be above your custom view, with the height set to matchParent?