0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【尺寸設(shè)置】 通用屬性

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-05-29 14:59 ? 次閱讀

尺寸設(shè)置

用于設(shè)置組件的寬高、邊距。

說明:
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

屬性

名稱參數(shù)說明描述
width[Length]設(shè)置組件自身的寬度,缺省時(shí)使用元素自身內(nèi)容需要的寬度。若子組件的寬大于父組件的寬,則會(huì)畫出父組件的范圍。 從API version 9開始,該接口支持在ArkTS卡片中使用。 從API version 10開始,該接口支持calc計(jì)算特性。
height[Length]設(shè)置組件自身的高度,缺省時(shí)使用元素自身內(nèi)容需要的高度。若子組件的高大于父組件的高,則會(huì)畫出父組件的范圍。 從API version 9開始,該接口支持在ArkTS卡片中使用。 從API version 10開始,該接口支持calc計(jì)算特性。
size{ width?: [Length], height?: [Length] }設(shè)置高寬尺寸。 從API version 9開始,該接口支持在ArkTS卡片中使用。 從API version 10開始,該接口支持calc計(jì)算特性。
padding[Padding][Length]
margin[Margin][Length]
constraintSize{ minWidth?: [Length], maxWidth?: [Length], minHeight?: [Length], maxHeight?: [Length] }設(shè)置約束尺寸,組件布局時(shí),進(jìn)行尺寸范圍限制。constraintSize的優(yōu)先級高于Width和Height。取值結(jié)果參考[constraintSize取值對width/height影響]。 默認(rèn)值: { minWidth: 0, maxWidth: Infinity, minHeight: 0, maxHeight: Infinity } 從API version 9開始,該接口支持在ArkTS卡片中使用。 從API version 10開始,該接口支持calc計(jì)算特性。

constraintSize取值對width/height影響

缺省值結(jié)果
/max(minWidth/minHeight, min(maxWidth/maxHeight, width/height))
maxWidth/maxHeightmax(minWidth/minHeight, width/height)
minWidth/minHeightmin(maxWidth/maxHeight, width/height)
width/heightmaxWidth/maxHeight > minWidth/minHeight時(shí)使用組件自身布局邏輯, 結(jié)果在maxWidth/maxHeight與minWidth/minHeight之間。 其他情況結(jié)果為max(minWidth/minHeight, maxWidth/maxHeight)。
maxWidth/maxHeight && width/heightminWidth/minHeight
minWidth/minHeight && width/height使用組件自身布局邏輯,最終結(jié)果不超過maxWidth/maxHeight
maxWidth/maxHeight && minWidth/minHeightwidth/height,根據(jù)其他布局屬性可能拉伸或者壓縮。
maxWidth/maxHeight && minWidth/minHeight && width/height使用父容器傳遞的布局限制進(jìn)行布局。HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿

新文檔.png

示例

// xxx.ets
@Entry
@Component
struct SizeExample {
  build() {
    Column({ space: 10 }) {
      Text('margin and padding:').fontSize(12).fontColor(0xCCCCCC).width('90%')
      Row() {
        // 寬度80 ,高度80 ,外邊距20(藍(lán)色區(qū)域),內(nèi)邊距10(白色區(qū)域)
        Row() {
          Row().size({ width: '100%', height: '100%' }).backgroundColor(Color.Yellow)
        }
        .width(80)
        .height(80)
        .padding(10)
        .margin(20)
        .backgroundColor(Color.White)
      }.backgroundColor(Color.Blue)

      Text('constraintSize').fontSize(12).fontColor(0xCCCCCC).width('90%')
      Text('this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text')
        .width('90%')
        .constraintSize({ maxWidth: 200 })

      Text('layoutWeight').fontSize(12).fontColor(0xCCCCCC).width('90%')
      // 父容器尺寸確定時(shí),設(shè)置了layoutWeight的子元素在主軸布局尺寸按照權(quán)重進(jìn)行分配,忽略本身尺寸設(shè)置。
      Row() {
        // 權(quán)重1,占主軸剩余空間1/3
        Text('layoutWeight(1)')
          .size({ width: '30%', height: 110 }).backgroundColor(0xFFEFD5).textAlign(TextAlign.Center)
          .layoutWeight(1)
        // 權(quán)重2,占主軸剩余空間2/3
        Text('layoutWeight(2)')
          .size({ width: '30%', height: 110 }).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
          .layoutWeight(2)
        // 未設(shè)置layoutWeight屬性,組件按照自身尺寸渲染
        Text('no layoutWeight')
          .size({ width: '30%', height: 110 }).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
      }.size({ width: '90%', height: 140 }).backgroundColor(0xAFEEEE)
      // calc計(jì)算特性
      Text('calc:').fontSize(12).fontColor(0xCCCCCC).width('90%')
      Text('calc test').fontSize(50).fontWeight(FontWeight.Bold).backgroundColor(0xFFFAF0).textAlign(TextAlign.Center)
        .margin('calc(25vp*2)')
        .size({width:'calc(90%)', height:'calc(50vp + 10%)'})
    }.width('100%').margin({ top: 5 })
  }
}

size

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • 鴻蒙
    +關(guān)注

    關(guān)注

    57

    文章

    2294

    瀏覽量

    42634
收藏 人收藏

    評論

    相關(guān)推薦

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【位置設(shè)置通用屬性

    設(shè)置組件的對齊方式、布局方向和顯示位置。
    的頭像 發(fā)表于 05-31 11:17 ?847次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【位置<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【圖片邊框設(shè)置通用屬性

    從API Version 9開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
    的頭像 發(fā)表于 05-31 09:41 ?686次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【圖片邊框<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS聲明開發(fā)范式

    基于ArkTS聲明開發(fā)范式的方舟開發(fā)框架是一套開發(fā)極簡、高性能、
    發(fā)表于 01-17 15:09

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【按鍵事件】

    按鍵事件指組件與鍵盤、遙控器等按鍵設(shè)備交互時(shí)觸發(fā)的事件,適用于所有可獲焦組件,例如Button。對于Text,Image等默認(rèn)不可獲焦的組件,可以設(shè)置focusable屬性為true后使用按鍵事件。
    的頭像 發(fā)表于 05-28 18:12 ?758次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【按鍵事件】

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【邊框設(shè)置通用屬性

    從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
    的頭像 發(fā)表于 05-31 09:48 ?723次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【邊框<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【背景設(shè)置通用屬性

    從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
    的頭像 發(fā)表于 05-31 15:22 ?506次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【背景<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【透明度設(shè)置通用屬性

    從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
    的頭像 發(fā)表于 06-03 15:59 ?468次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【透明度<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【顯隱控制】 通用屬性

    控制當(dāng)前組件顯示或隱藏。注意,即使組件處于隱藏狀態(tài),在頁面刷新時(shí)仍存在重新創(chuàng)建過程,因此當(dāng)對性能有嚴(yán)格要求時(shí)建議使用[條件渲染]代替。 默認(rèn)值:Visibility.Visible 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發(fā)表于 06-03 14:46 ?500次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【顯隱控制】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【形狀裁剪】 通用屬性

    參數(shù)為相應(yīng)類型的組件,按指定的形狀對當(dāng)前組件進(jìn)行裁剪;參數(shù)為boolean類型時(shí),設(shè)置是否按照父容器邊緣輪廓進(jìn)行裁剪。 默認(rèn)值:false 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發(fā)表于 06-04 15:22 ?366次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【形狀裁剪】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【柵格設(shè)置通用屬性

    默認(rèn)占用列數(shù),指useSizeType屬性沒有設(shè)置對應(yīng)尺寸的列數(shù)(span)時(shí),占用的柵格列數(shù)。
    的頭像 發(fā)表于 06-05 09:28 ?316次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【柵格<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【菜單控制】 通用屬性

    為組件綁定彈出菜單,彈出菜單以垂直列表形式顯示菜單項(xiàng),可通過長按、點(diǎn)擊或鼠標(biāo)右鍵觸發(fā)。
    的頭像 發(fā)表于 06-06 09:17 ?451次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【菜單控制】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【多態(tài)樣式】 通用屬性

    設(shè)置組件不同狀態(tài)的樣式。 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發(fā)表于 06-07 09:48 ?323次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【多態(tài)樣式】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【前景色設(shè)置通用屬性

    設(shè)置組件的前景顏色或者根據(jù)智能取色策略設(shè)置前景顏色。
    的頭像 發(fā)表于 06-07 16:19 ?336次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【前景色<b class='flag-5'>設(shè)置</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【無障礙屬性通用屬性

    組件可以設(shè)置相應(yīng)的無障礙屬性和事件來更好地使用無障礙能力。
    的頭像 發(fā)表于 06-11 17:30 ?318次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【無障礙<b class='flag-5'>屬性</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發(fā)平臺(tái)支持列表【文本通用

    文本通用屬性目前只針對包含文本元素的組件,設(shè)置文本樣式。
    的頭像 發(fā)表于 06-13 15:09 ?366次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺(tái)</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【文本<b class='flag-5'>通用</b>】