HarmonyOS 如何实现让里层view的宽度等于外层view的宽度

HarmonyOS
2025-01-09 15:25:34
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

可以通过border来实现,参考示例如下:

import { LengthMetrics } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  @State value: string = '登录'
  @State sizeValue: string = ''
  @State message: string = 'Hello World';
  @State dWidth: Length = 0

  build() {
    NavDestination() {
      RelativeContainer() {
        Column() { /// 1号
          Column() { /// 2号
            Divider()
              .height(8)
              .width(this.dWidth)
              .backgroundColor($r("app.color.colorPrimary"))
              .position({
                start: LengthMetrics.px(0),
                end: LengthMetrics.px(0),
                bottom: LengthMetrics.px(0)
              })

            Text('登录')
              .fontColor("#333")
              .fontSize(30)
              .fontWeight(FontWeight.Bold)
              .onAreaChange((oldValue: Area, newValue: Area) => {
                console.info(JSON.stringify(newValue))
                console.log('输出:', newValue)
                console.log('输出:', newValue.width)
                console.log('输出:', typeof newValue.width)
                this.dWidth = newValue.width
              })
          }
          .width("auto")
          .justifyContent(FlexAlign.End)
          .alignItems(HorizontalAlign.Start)
          .margin({
            top: 80,
            left: 10
          })

        }
        .alignItems(HorizontalAlign.Start)
        .backgroundColor($r('app.color.white'))
        .width('100%')
        .height('100%')
        .padding({
          left: '35',
          right: '25'
        })
      }
      .padding({ top: AppStorage.get<number>('statusBarHeight') })
    }
    .hideTitleBar(true)
  }
}
分享
微博
QQ
微信
回复
2025-01-09 18:30:58
相关问题
RelativeContainer如何多个view居中
1677浏览 • 1回复 待解决
HarmonyOS 如何实现View边缘模糊效果
809浏览 • 1回复 待解决
HarmonyOS 单纯渐变View
718浏览 • 2回复 待解决
怎么设置元素最大宽度最小宽度
563浏览 • 1回复 待解决
关于picker-view问题
7638浏览 • 1回复 待解决
HarmonyOS 获取view在屏幕坐标
367浏览 • 1回复 待解决
HarmonyOS 如何遍历获取page中所有view
188浏览 • 1回复 待解决
HarmonyOS view动态添加
455浏览 • 1回复 待解决
HarmonyOS 如何添加一个悬浮View
458浏览 • 1回复 待解决
HarmonyOS 如何获取组件宽度
581浏览 • 1回复 待解决
如何获取当前组件宽度
607浏览 • 1回复 待解决
请问如何获取窗口宽度
2090浏览 • 1回复 待解决