将本机页脚视图添加到 webview

2024-01-08

我有一个WebView和我想在下面添加的本机自定义视图WebView。我试过包裹WebView里面一个ScrollView,虽然这正是我想要的,但滚动性能确实很滞后,如果用户点击屏幕滚动滚动条并不会像应有的那样停止滚动。

我想到的另一种方法是膨胀WebView放入包装纸中FrameLayout我的页脚视图位于顶部WebView,然后以某种方式扩展WebView高度以适应页脚大小,将页脚视图推到底部WebViews 高度,然后监视滚动WebView来移动页脚。

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

如何扩展可滚动内容WebView?我怎样才能将本机页脚设置在下面WebView内容?

EDIT:

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

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

包裹一个简单的Webview,带有页脚(LinearLayout, RelativeLayout等)内ObservableScrollView,而不是一个ObservableWebView。我无法详细说明,因为您尚未添加任何布局文件。

EDIT:

活动.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> 

活动.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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将本机页脚视图添加到 webview 的相关文章

随机推荐