将本地页脚视图添加到Webview [英] Add native footer view to webview

查看:110
本文介绍了将本地页脚视图添加到Webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebView和一个要添加到WebView下面的本机自定义视图.我试过将WebView包装在ScrollView内,尽管这确实符合我的要求,但滚动性能确实很差,并且如果用户在滚动滚动屏幕时无法滚动,则滚动不会像应有的那样停止滚动.

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.

我在想的另一种方法是将WebView填充到包装器FrameLayout中,并使我的页脚视图位于WebView的顶部,然后以某种方式扩展WebView的高度以适应页脚的大小,然后按页脚视图到WebView高度的末尾,然后监视WebView的滚动以将页脚与之一起移动.

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 WebViews height and then monitor the scroll of the WebView to move the footer with it.

我已经设置了基类,我的问题是扩展WebView中的可滚动内容,然后将页脚推到WebView内容的底部.主要问题是WebView不是您的典型android视图,并且页面内容异步加载(因此内容大小会发生变化).

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 WebViews 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).

如何扩展WebView的可滚动内容?以及如何在WebView内容下方设置本机页脚?

How can I extend the scrollable content of a WebView? And how can I set the native footer below the WebView content?

我实际上并没有使用xml,而是使用如下代码构建视图:

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);
}
}

推荐答案

ObservableScrollView而不是ObservableWebView内的页脚(LinearLayoutRelativeLayout等)包装简单的Webview .由于您尚未添加任何布局文件,因此我无法详细介绍.

Wrap a simple Webview, with a footer (LinearLayout, RelativeLayout, etc) inside an ObservableScrollView, rather than an ObservableWebView. I cannot go into details as you haven't added any layout files.

编辑:

Activity.xml :

<LinearLayout   
   android:layout_width="match parent"  
   android:layout_height="match parent"  
   android:orientation="vertical">  
   <com.github.ksoichiro.android.observablescrollview.ObservableScrollView
           android:id="@+id/viewObj" 
           android:layout_width="match parent"  
           android:layout_height="wrap_content">
    <!-- Webview and footer programatically added here -->
    </com.github.ksoichiro.android.observablescrollview.ObservableScrollView
</LinearLayout> 

Activity.java :

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 WebView(getContext());
mFooterContainer = new FrameLayout(getContext());

mObservableScrollView = (ObservableScrollView) findViewbyId(R.id.viewObj);
mObservableScrollView.addView(mWebView, webviewParams);
mObservableScrollView.addView(mFooterContainer, footerParams);

这篇关于将本地页脚视图添加到Webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆