OpenHarmony开源社区
直播中

ss

8年用户 8762经验值
擅长:电源/新能源 制造/封装 RF/无线
私信 关注
[问答]

harmonyos的WebView会遮挡住其他控件是为什么?怎么解决?

我的资源配置是这样的。只要webview的高度比scrollview的高度高,则会覆盖下面的button,这是系统bug还是我配置问题?


回帖(2)

ss

2022-3-24 11:23:36
可以考虑去掉Scrillview看一下
代码如下

    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:orientation="vertical">
            ohos:id="$+id:webview"
        ohos:height="0fp"
        ohos:weight="1"
        ohos:width="match_parent">
   
            ohos:height="100fp"
        ohos:width="match_parent"
        ohos:background_element="$color:blue"
        ohos:text="tetxtx"
        ohos:text_size="24vp"
        ohos:text_alignment="center"/>

package com.example.jsdemo.slice;
import com.example.jsdemo.ResourceTable;
import com.example.jsdemo.utils.HiLogUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.webengine.*;
import ohos.media.image.PixelMap;
public class WebviewSlice extends AbilitySlice {
    private static final String EXAMPLE_URL = "https://main.m.taobao.com/";
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_webview_slice);
        WebView webView = (WebView) findComponentById(ResourceTable.Id_webview);
        WebConfig webConfig = webView.getWebConfig();
        webConfig.setJavaScriptPermit(true);
        webConfig.setWebStoragePermit(true);
        webConfig.setDataAbilityPermit(true);
        webConfig.setLoadsImagesPermit(true);
        webConfig.setMediaAutoReplay(true);
        webConfig.setLocationPermit(true);
        webConfig.setSecurityMode(WebConfig.SECURITY_SELF_ADAPTIVE);
        webView.setWebAgent(new WebAgent() {
            @Override
            public void onLoadingPage(WebView webview, String url, PixelMap favicon) {
                super.onLoadingPage(webview, url, favicon);
                // 页面开始加载时自定义处理
                HiLogUtils.PrintLog("onLoadingPage======>>>");
            }
            @Override
            public void onPageLoaded(WebView webview, String url) {
                super.onPageLoaded(webview, url);
                // 页面加载结束后自定义处理
                HiLogUtils.PrintLog("onPageLoaded======>>>");
            }
            @Override
            public void onLoadingContent(WebView webview, String url) {
                super.onLoadingContent(webview, url);
                // 加载资源时自定义处理
                HiLogUtils.PrintLog("onLoadingContent======>>>");
            }
            @Override
            public void onError(WebView webview, ResourceRequest request, ResourceError error) {
                super.onError(webview, request, error);
                // 发生错误时自定义处理
                HiLogUtils.PrintLog("onError======>>>"+error.getInfo());
            }
        });
        webView.load(EXAMPLE_URL);
    }
}
效果如图所示


举报

ss

2022-3-24 11:24:52
建议代码部分不要截图,直接贴代码(论坛的编辑器支持显示代码)。这样方便小伙伴验证问题。

1. 没有跑代码,我估计是你配置的问题,ScrollView+DirectionalLayout,一般情况要把`DirectionalLayout`的高度设置成包裹内容`ohos:height="match_content"`,你这样设置试一试。

2. 鸿蒙的WebView确实会遮挡其他控件,但不是在这种布局。在DependentLayout或StackLayout中使用WebView会遮挡其它控件。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分