HarmonyOS 关于 margin 设置百分比的问题
设置了 margin top 40%,但是看距离不对(横竖屏都不对)
import { window } from '@kit.ArkUI';
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
onPageShow(): void {
// window.getLastWindow(getContext(this)).then((lastWindow) => {
// // 横屏
// lastWindow.setPreferredOrientation(window.Orientation.LANDSCAPE_INVERTED);
// // 全屏
// lastWindow.setWindowLayoutFullScreen(true);
// // 设置状态栏和导航条隐藏
// lastWindow.setSpecificSystemBarEnabled('status', false);
// })
}
build() {
RelativeContainer() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
top: { anchor: "__container__", align: VerticalAlign.Top },
middle: { anchor: "__container__", align: HorizontalAlign.Center }
})
.margin({ top: '40%' })
.backgroundColor(Color.Blue)
}
.width('100%')
.height('100%')
}
}
- 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.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS 关于组件height百分比显示问题
1113浏览 • 1回复 待解决
HarmonyOS ArkTS百分比变量设置
589浏览 • 1回复 待解决
HarmonyOS 组件高度按照屏幕宽度的百分比展示
1337浏览 • 1回复 待解决
HarmonyOS linearGradient里边的百分比是什么意思
785浏览 • 1回复 待解决
HarmonyOS 如何获取设置中显示电量百分比开关是否打开
710浏览 • 1回复 待解决
HarmonyOS webview加载网页如何实现加载进度百分比
833浏览 • 1回复 待解决
HarmonyOS margin中top和bottom使用百分比时,算出实际的px不对 17:22:04
643浏览 • 1回复 待解决
HarmonyOS 怎么让一个布局不设置百分比,三等分
838浏览 • 1回复 待解决
#鸿蒙学习大百科#如何将小数转化为百分比?
949浏览 • 2回复 待解决
HarmonyOS 有类似于guideline这样可以区分容器百分比的组件吗?
654浏览 • 1回复 待解决
HarmonyOS hdc shell SP_daemon -N 2 -c 如何获取手机cpu百分比
954浏览 • 1回复 待解决
给组件的 .borderRadius("20%")圆角角度设置百分比值不生效
1107浏览 • 1回复 待解决
子元素使用position百分比定位,父元素设置padding.top和padding.left的行为不正确
1033浏览 • 1回复 待解决
HarmonyOS 将URL编码(百分比编码)的字符串转化为对应的汉字应该使用哪个API?
1058浏览 • 1回复 待解决
HarmonyOS 设置margin无效
616浏览 • 1回复 待解决
HarmonyOS .width('100%')和margin同时设置,左右margin无效
967浏览 • 1回复 待解决
HarmonyOS 关于alertDialog样式设置的问题
629浏览 • 1回复 待解决
HarmonyOS 关于代理提醒的设置问题
1432浏览 • 1回复 待解决
HarmonyOS 组件设置margin左右20,width 100% margin会失效
3137浏览 • 2回复 待解决
关于DES加密的设置问题
876浏览 • 1回复 待解决
HarmonyOS margin不生效问题
1070浏览 • 1回复 待解决
HarmonyOS 关于动态设置组件宽度的问题
1168浏览 • 1回复 待解决
HarmonyOS TextInput设置showCounter时,margin失效
743浏览 • 1回复 待解决
HarmonyOS 关于Tabs如何设置字体颜色的问题
640浏览 • 1回复 待解决
HarmonyOS CustomDialog怎么设置弹窗背板和左右的margin?
806浏览 • 1回复 待解决
RelativeContainer的margin起始点是锚点位置来计算的,margin设置百分比参考的是父容器的宽度而不是父容器的长宽。
RelativeContainer参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-container-relativecontainer.md
margin参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-universal-attributes-size.md#margin