那曲檬骨新材料有限公司

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

鴻蒙ArkTS聲明式開發:跨平臺支持列表【位置設置】 通用屬性

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-05-31 11:17 ? 次閱讀

位置設置

設置組件的對齊方式、布局方向和顯示位置。

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

屬性

名稱參數類型描述
align[Alignment]設置元素內容在元素繪制區域內的對齊方式。 只在Stack、Button、Marquee、StepperItem、text、TextArea、TextInput中生效,其中和文本相關的組件Marquee、text、TextArea、TextInput的align結果參考[textAlign]。 不支持textAlign屬性的組件則無法設置水平方向的文字對齊。 默認值:Alignment.Center 從API version 9開始,該接口支持在ArkTS卡片中使用。
direction[Direction]設置元素水平方向的布局。 默認值:Direction.Auto 從API version 9開始,該接口支持在ArkTS卡片中使用。
position[Position]絕對定位,設置元素左上角相對于父容器左上角偏移位置。在布局容器中,設置該屬性不參與父容器布局,即不占位,僅在繪制時進行位置調整。 適用于置頂顯示、懸浮按鈕等組件在父容器中位置固定的場景。 從API version 9開始,該接口支持在ArkTS卡片中使用。
markAnchor[Position]設置元素在位置定位時的錨點,以元素左上角作為基準點進行偏移。通常配合position和offset屬性使用,單獨使用時,效果類似offset API version 9及以前,默認值為: { x: 0, y: 0 } API version 10:無默認值。 從API version 9開始,該接口支持在ArkTS卡片中使用。
offset[Position]相對定位,設置元素相對于自身的偏移量。設置該屬性后子組件正常參與父容器布局,在繪制時基于父容器給予的offset做一次額外的偏移。 API version 9及以前,默認值為: { x: 0, y: 0 } API version 10:無默認值。 從API version 9開始,該接口支持在ArkTS卡片中使用。
alignRules9+{ left?: { anchor: string, align: [HorizontalAlign] }; right?: { anchor: string, align: [HorizontalAlign] }; middle?: { anchor: string, align: [HorizontalAlign] }; top?: { anchor: string, align: [VerticalAlign] }; bottom?: { anchor: string, align: [VerticalAlign] }; center?: { anchor: string, align: [VerticalAlign] } }指定相對容器的對齊規則,僅當父容器為[RelativeContainer]時生效。 - left:設置左對齊參數。 - right:設置右對齊參數。 - middle:設置中間對齊的參數。 - top:設置頂部對齊的參數。 - bottom:設置底部對齊的參數。 - center:設置中心對齊的參數。 該接口支持在ArkTS卡片中使用。說明:- anchor:設置作為錨點的組件的id值。 - align:設置相對于錨點組件的對齊方式。

示例

示例1

// xxx.ets
@Entry
@Component
struct PositionExample1 {
  build() {
    Column() {
      Column({ space: 10 }) {
        // 元素內容< 元素寬高,設置內容在與元素內的對齊方式
        Text('align').fontSize(9).fontColor(0xCCCCCC).width('90%')
        Stack() {
          Text('First show in bottom end').height('65%').backgroundColor(0xD2B48C)
          Text('Second show in bottom end').backgroundColor(0xF5DEB3).opacity(0.9)
        }.width('90%').height(50).margin({ top: 5 }).backgroundColor(0xFFE4C4)
        .align(Alignment.BottomEnd)
        Stack() {
          Text('top start')
        }.width('90%').height(50).margin({ top: 5 }).backgroundColor(0xFFE4C4)
        .align(Alignment.TopStart)

        // 父容器設置direction為Direction.Ltr,子元素從左到右排列
        Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%')
        Row() {
          Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
          Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
          Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
          Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
        }
        .width('90%')
        .direction(Direction.Ltr)
        // 父容器設置direction為Direction.Rtl,子元素從右到左排列
        Row() {
          Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.End)
          Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.End)
          Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.End)
          Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.End)
        }
        .width('90%')
        .direction(Direction.Rtl)
      }
    }
    .width('100%').margin({ top: 5 })
  }
}

align.png

示例2

鴻蒙文檔.png

`HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789v直接拿`

// xxx.ets
@Entry
@Component
struct PositionExample2 {
  build() {
    Column({ space: 20 }) {
      // 設置子組件左上角相對于父組件左上角的偏移位置
      Text('position').fontSize(12).fontColor(0xCCCCCC).width('90%')
      Row() {
        Text('1').size({ width: '30%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
          .textAlign(TextAlign.Center)
        Text('2 position(30, 10)')
          .size({ width: '60%', height: '30' })
          .backgroundColor(0xbbb2cb)
          .border({ width: 1 })
          .fontSize(16)
          .align(Alignment.Start)
          .position({ x: 30, y: 10 })
        Text('3').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
          .textAlign(TextAlign.Center)
        Text('4 position(50%, 70%)')
          .size({ width: '50%', height: '50' })
          .backgroundColor(0xbbb2cb)
          .border({ width: 1 })
          .fontSize(16)
          .position({ x: '50%', y: '70%' })
      }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })

      // 相對于起點偏移,其中x為最終定位點距離起點水平方向間距,x >0往左,反之向右。
      // y為最終定位點距離起點垂直方向間距,y >0向上,反之向下
      Text('markAnchor').fontSize(12).fontColor(0xCCCCCC).width('90%')
      Stack({ alignContent: Alignment.TopStart }) {
        Row()
          .size({ width: '100', height: '100' })
          .backgroundColor(0xdeb887)
        Text('text')
          .fontSize('30px')
          .textAlign(TextAlign.Center)
          .size({ width: 25, height: 25 })
          .backgroundColor(Color.Green)
          .markAnchor({ x: 25, y: 25 })
        Text('text')
          .fontSize('30px')
          .textAlign(TextAlign.Center)
          .size({ width: 25, height: 25 })
          .backgroundColor(Color.Green)
          .markAnchor({ x: -100, y: -25 })
        Text('text')
          .fontSize('30px')
          .textAlign(TextAlign.Center)
          .size({ width: 25, height: 25 })
          .backgroundColor(Color.Green)
          .markAnchor({ x: 25, y: -25 })
      }.margin({ top: 25 }).border({ width: 1, style: BorderStyle.Dashed })

      // 相對定位,x >0向右偏移,反之向左,y >0向下偏移,反之向上
      Text('offset').fontSize(12).fontColor(0xCCCCCC).width('90%')
      Row() {
        Text('1').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
          .textAlign(TextAlign.Center)
        Text('2  offset(15, 30)')
          .size({ width: 120, height: '50' })
          .backgroundColor(0xbbb2cb)
          .border({ width: 1 })
          .fontSize(16)
          .align(Alignment.Start)
          .offset({ x: 15, y: 30 })
        Text('3').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
          .textAlign(TextAlign.Center)
        Text('4 offset(-10%, 20%)')
          .size({ width: 100, height: '50' })
          .backgroundColor(0xbbb2cb)
          .border({ width: 1 })
          .fontSize(16)
          .offset({ x: '-5%', y: '20%' })
      }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })
    }
    .width('100%').margin({ top: 25 })
  }
}

position.png

審核編輯 黃宇

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 鴻蒙
    +關注

    關注

    57

    文章

    2392

    瀏覽量

    43050
收藏 人收藏

    評論

    相關推薦

    鴻蒙ArkTS聲明開發平臺支持列表【圖片邊框設置通用屬性

    從API Version 9開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。
    的頭像 發表于 05-31 09:41 ?856次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    HarmonyOS/OpenHarmony應用開發-ArkTS聲明開發范式

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

    鴻蒙ArkTS聲明開發平臺支持列表【按鍵事件】

    按鍵事件指組件與鍵盤、遙控器等按鍵設備交互時觸發的事件,適用于所有可獲焦組件,例如Button。對于Text,Image等默認不可獲焦的組件,可以設置focusable屬性為true后使用按鍵事件。
    的頭像 發表于 05-28 18:12 ?919次閱讀
    <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'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【按鍵事件】

    鴻蒙ArkTS聲明開發平臺支持列表【尺寸設置通用屬性

    從API Version 7開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。
    的頭像 發表于 05-29 14:59 ?622次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【邊框設置通用屬性

    從API Version 7開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。
    的頭像 發表于 05-31 09:48 ?1103次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【背景設置通用屬性

    從API Version 7開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。
    的頭像 發表于 05-31 15:22 ?794次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【透明度設置通用屬性

    從API Version 7開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。
    的頭像 發表于 06-03 15:59 ?688次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【顯隱控制】 通用屬性

    控制當前組件顯示或隱藏。注意,即使組件處于隱藏狀態,在頁面刷新時仍存在重新創建過程,因此當對性能有嚴格要求時建議使用[條件渲染]代替。 默認值:Visibility.Visible 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發表于 06-03 14:46 ?640次閱讀
    <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'>開發</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><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【形狀裁剪】 通用屬性

    參數為相應類型的組件,按指定的形狀對當前組件進行裁剪;參數為boolean類型時,設置是否按照父容器邊緣輪廓進行裁剪。 默認值:false 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發表于 06-04 15:22 ?517次閱讀
    <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'>開發</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><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【柵格設置通用屬性

    默認占用列數,指useSizeType屬性沒有設置對應尺寸的列數(span)時,占用的柵格列數。
    的頭像 發表于 06-05 09:28 ?441次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【菜單控制】 通用屬性

    為組件綁定彈出菜單,彈出菜單以垂直列表形式顯示菜單項,可通過長按、點擊或鼠標右鍵觸發。
    的頭像 發表于 06-06 09:17 ?764次閱讀
    <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'>開發</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><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【多態樣式】 通用屬性

    設置組件不同狀態的樣式。 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發表于 06-07 09:48 ?454次閱讀
    <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'>開發</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><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【前景色設置通用屬性

    設置組件的前景顏色或者根據智能取色策略設置前景顏色。
    的頭像 發表于 06-07 16:19 ?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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【無障礙屬性通用屬性

    組件可以設置相應的無障礙屬性和事件來更好地使用無障礙能力。
    的頭像 發表于 06-11 17:30 ?436次閱讀
    <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'>開發</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>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【文本通用

    文本通用屬性目前只針對包含文本元素的組件,設置文本樣式。
    的頭像 發表于 06-13 15:09 ?541次閱讀
    <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'>開發</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>】
    黄金城百家乐官网下载| 现场百家乐平台源码| 百家乐娱乐优惠| 大发888下载大发888娱乐城| 澄城县| 百家乐官网真人荷官网| 百家乐游戏补牌规则| 太阳城ktv| 清水河县| 百家乐官网游戏什么时间容易出对| 圣安娜百家乐包杀合作| 8大胜娱乐| 百家乐官网保单机解码| 百家乐追注法| 双桥区| 网上百家乐官网群的微博| 威尼斯人娱乐城在线赌博网站| 阿拉善盟| 机器百家乐官网作弊| 百家乐群必胜打朽法| 百家乐官网作弊工具| 百家乐官网奥| 巴比伦百家乐的玩法技巧和规则| 国际环球娱乐| 24山什么来龙是真龙| 大发888官方c8| 粤港澳百家乐官网娱乐网| 百家乐牌盒| 六合彩 开奖| 百家乐官网正式版| 威尼斯人娱乐城博彩| 百家乐官网系统足球博彩通| 作弊百家乐赌具| 百家乐官网从哪而来| 百家乐投注网中国体育| 阿巴嘎旗| 赌百家乐怎样能赢| 河间市| 皇冠百家乐赢钱皇冠| 沅江市| 百家乐7杀6|