gpt4 book ai didi

android - 将 native 页脚 View 添加到 webview

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:36 25 4
gpt4 key购买 nike

我有一个 WebView和我想在 WebView 下面添加的原生自定义 View .我试过包装 WebViewScrollView 里面,虽然这正是我想要的,但滚动性能确实很滞后,如果用户滑动滚动条,点击屏幕不会像它应该的那样停止滑动。

我想到的另一种方法是膨胀 WebView放入 wrapper 中 FrameLayout我的页脚 View 位于 WebView 之上,然后以某种方式扩展 WebView高度以适应页脚大小,将页脚 View 推到 WebView 的末尾s 高度,然后监视 WebView 的滚动移动页脚。

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

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

编辑:

我实际上并没有使用 xml, View 是用这样的代码构建的:

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,在 ObservableScrollView 中使用页脚(LinearLayoutRelativeLayout 等),而不是 ObservableWebView。我无法详细说明,因为您尚未添加任何布局文件。

编辑:

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

关于android - 将 native 页脚 View 添加到 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31243771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com