当Web组件内容过长时,出现了布局问题,底部固定栏文字超出屏幕范围并被截断,该如何解决?
问题效果预览:

示例代码:
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebScroll {
controller: webview.WebviewController = new webview.WebviewController();
private scrollerForScroll: Scroller = new Scroller();
build() {
Column() {
Text('标题');
Scroll(this.scrollerForScroll) {
Column() {
Text('下面是Web组件');
Web({ src: 'https://developer.huawei.com/consumer/', controller: this.controller })
.height('100%');
Text('文字1');
Text('文字2');
Text('文字3');
};
}
.scrollBar(BarState.Off)
.scrollable(ScrollDirection.Vertical);
Text('底部固定栏');
};
}
} layoutWeight属性可以实现高度自适应效果,如果父容器尺寸确定时,设置了layoutWeight属性且layoutWeight属性生效值大于0的子元素会从主轴剩余空间中按照各自所设置的权重占比分配尺寸,忽略元素本身尺寸设置,自适应占满剩余空间。将Scroll组件设置layoutWeight(1)即可自适应高度解决此问题。
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebScroll {
controller: WebviewController = new webview.WebviewController();
private scrollerForScroll: Scroller = new Scroller();
build() {
Column() {
Text('标题');
Scroll(this.scrollerForScroll) {
Column() {
Text('下面是Web组件');
Web({ src: 'www.example.com', controller: this.controller })
.nestedScroll({ scrollForward: NestedScrollMode.SELF_FIRST, scrollBackward: NestedScrollMode.PARENT_FIRST })
.height('100%')
.fileAccess(false)
.geolocationAccess(false);
Text('文字1');
Text('文字2');
Text('文字3');
};
}
.scrollBar(BarState.Off)
.layoutWeight(1)
.scrollable(ScrollDirection.Vertical);
Text('底部固定栏');
};
}
}