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

HarmonyOS
2025-01-09 15:25:34
1492浏览
收藏 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)
  }
}
  • 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.
  • 57.
  • 58.
  • 59.
  • 60.
分享
微博
QQ
微信
回复
2025-01-09 18:30:58


相关问题
RelativeContainer如何多个view居中
2019浏览 • 1回复 待解决
HarmonyOS 如何实现View边缘模糊效果
1290浏览 • 1回复 待解决
HarmonyOS 单纯渐变View
979浏览 • 2回复 待解决
怎么设置元素最大宽度最小宽度
903浏览 • 1回复 待解决
HarmonyOS 如何遍历获取page中所有view
500浏览 • 1回复 待解决
关于picker-view问题
8088浏览 • 1回复 待解决
HarmonyOS 如何获取组件宽度
861浏览 • 1回复 待解决
如何获取当前组件宽度
944浏览 • 1回复 待解决
HarmonyOS 获取view在屏幕坐标
770浏览 • 1回复 待解决
HarmonyOS view动态添加
832浏览 • 1回复 待解决
HarmonyOS 如何添加一个悬浮View
903浏览 • 1回复 待解决