鸿蒙小记
自定义Component不能作为根容器
自定义Component不能直接作为@Entry注解的组件的根组件,如果想用,需要套一层系统的容器组件
Scroll无法滚动
Scroll的直接子组件,滚动方向上的尺寸,一定不能设置为100%,设置后无法滚动。
Scroll() {
Row()
.height('100%')
}
.scrollable(ScrollDirection.Vertical)
Scroll的直接子组件和父组件链上的尺寸需要设置合理的值(基本上就是错估的"100%"的含义)
Column() {
this.actionBar()
Navigation(this.subStack) {
this.accountContentView()
}
.width("100%")
}
.width("100%")
.height("100%")
@Builder
accountContentView() {
Scroll() {
Column() {...}
.width("100%")
}
.width("100%")
.scrollable(ScrollDirection.Vertical)
}
假设accountContentView()中Scroll的内容足够滚动,且actionBar()高度是一个固定小的数值。现在这样没办法滚动,因为Navigation高度是auto,实际大小会保持Scroll内Column的大小,无法滚动;
如果将Navigation高度设置为100%,那么也有可能无法滚动,*100%*是将Navigation高度设置为根Column的高度,如果Scroll的内容高度小于根Column的高度也无法滚动。
能够滚动是:Scroll的直接子组件在滚动方向上的尺寸大于scroll。
RelativeContainer chainWeight存在顺序问题
ItemPlaneView()
.id("item1")
.alignRules({
left: { anchor: "__container__", align: HorizontalAlign.Start },
right: { anchor: "item2", align: HorizontalAlign.Start },
top: { anchor: "title", align: VerticalAlign.Bottom }
})
.chainWeight({ horizontal: 1 })
如果chainWeight放在alignRules之前,运行会报错:
Reason:Signal:SIGSEGV(SEGV_MAPERR)@0x0000000000000110 probably caused by NULL pointer dereference
SVG着色后没有图形,颜色全是设置的颜色
鸿蒙对svg的着色只对path的fill属性有效,对stroke无效
显示沙箱内文件图片
构造 file://${BUNDLE_NAME}${pathDir}/${imgName} 的格式,Image直接使用就行
private getAvatarRes(): ResourceStr {
const bundleName = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).name;
const avatarFullPath = context.filesDir + "/avatar.jpg";
const result = `file://${bundleName}${avatarFullPath}`;
console.log("path:" + result) //输出:path:file://com.test.example/data/storage/el2/base/haps/entry/files/avatar.jpg
return result;
}
Image(this.getAvatarRes())