鸿蒙的WebView会遮挡其他控件问题

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

鸿蒙的WebView会遮挡其他控件问题-鸿蒙开发者社区

webview
遮挡
层级
2021-09-08 16:57:58
浏览
收藏 1
回答 3
回答 3
按赞同
/
按时间
红叶亦知秋
3

可以考虑去掉Scrillview看一下

代码如下

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:orientation="vertical">
    <ohos.agp.components.webengine.WebView
        ohos:id="$+id:webview"
        ohos:height="0fp"
        ohos:weight="1"
        ohos:width="match_parent">
    </ohos.agp.components.webengine.WebView>
    <Text
        ohos:height="100fp"
        ohos:width="match_parent"
        ohos:background_element="$color:blue"
        ohos:text="tetxtx"
        ohos:text_size="24vp"
        ohos:text_alignment="center"/>



</DirectionalLayout>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
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);
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.

 

效果如图所示

 

答案引用于:华为开发者联盟开发者支持团队

已于2021-9-10 15:04:02修改
分享
微博
QQ
微信
回复
2021-09-10 15:03:08
爱吃土豆丝的打工人
1

把你的button的高度固定了,然后在scrollview外部加一个DirectionlLayout高度比例设为1  然后你上面的webView就不会遮挡住你的button按钮

分享
微博
QQ
微信
回复
2021-09-10 09:50:29
没用的喵叔
1

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

-----

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

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

分享
微博
QQ
微信
回复
2021-09-13 14:37:32


相关问题
HarmonyOS webview输入框被遮挡
456浏览 • 1回复 待解决
HarmonyOS 底部遮挡问题处理
417浏览 • 1回复 待解决
HarmonyOS tabbar 区域遮挡问题
295浏览 • 1回复 待解决
关于sidebar侧边栏遮挡导航栏问题
937浏览 • 1回复 待解决
关于软键盘弹出遮挡问题
1556浏览 • 1回复 待解决
HarmonyOS 使用Webview闪退
436浏览 • 1回复 待解决
HarmonyOS 刷新控件问题
604浏览 • 1回复 待解决
HarmonyOS saveButton控件问题
559浏览 • 1回复 待解决
HarmonyOS 容器和控件布局问题
523浏览 • 1回复 待解决
使用TextPicker控件显示异常问题
1272浏览 • 1回复 待解决
HarmonyOS web控件执行多次问题
1021浏览 • 1回复 待解决
HarmonyOS 关于跳转其他app问题
527浏览 • 1回复 待解决
HarmonyOS 安全控件使用问题
763浏览 • 1回复 待解决
HarmonyOS Tabs控件fadingEdge问题
1068浏览 • 1回复 待解决
HarmonyOS webview打不开问题
487浏览 • 1回复 待解决