<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Go Gio 實戰(zhàn):煮蛋計時器的實現(xiàn) 06 — 帶邊距的按鈕

          共 2178字,需瀏覽 5分鐘

           ·

          2021-12-09 13:10

          繼續(xù)本系列第 6 篇。

          01 本節(jié)目標(biāo)

          在按鈕兩邊加上空白,即帶邊距的按鈕,如下圖。

          Button with margin

          02 關(guān)鍵代碼

          為了突出結(jié)構(gòu),主要關(guān)注下面關(guān)鍵點:

          1. 使用 layout.Inset 定義邊距
          2. 布局這些邊距
          3. 在這些邊距內(nèi)創(chuàng)建按鈕

          代碼如下:

          layout.Flex{
          ????//?...
          }.Layout(gtx,?
          ????layout.Rigid(
          ????????func(gtx?C)?D?{
          ????????????//?1、使用?layout.Inset?定義邊距
          ????????????margin?:=?layout.Inset{
          ????????????????//?...
          ????????????}

          ????????????//?2、布局這些邊距
          ????????????margins.Layout(
          ????????????????
          ????????????????//?3、在這些邊距內(nèi)創(chuàng)建按鈕
          ????????????????func(gtx?C)?D?{
          ????????????????????btn?:=?material.Button(th,?&startButton,?"Start")
          ????????????????????return?btn.Layout(gtx)
          ????????????????},
          ????????????
          ????????????)

          ????????????}
          ????????}
          ????)????
          )

          03 代碼詳解

          上面就像一個中間有一個按鈕的甜甜圈。這個比喻形象嗎?

          Button inside inset

          邊距是使用 layout.Inset{} 構(gòu)建的。它是一個結(jié)構(gòu)體,定義了小部件周圍的空間:

          margins?:=?layout.Inset{
          ????Top:????unit.Dp(25),
          ????Bottom:?unit.Dp(25),
          ????Right:??unit.Dp(35),
          ????Left:???unit.Dp(35),
          }

          在這里,margins 使用設(shè)備獨(dú)立的單位:unit.Dp。如果你希望所有邊的邊距都相同,還有一個方便的 UniformInset( ),可以為你節(jié)省幾次按鍵操作。

          04 完整代碼

          以下是 system.FrameEvent 部分的完整代碼:

          case?system.FrameEvent:
          ????gtx?:=?layout.NewContext(&ops,?e)
          ????//?Let's?try?out?the?flexbox?layout?concept
          ????layout.Flex{
          ????????//?Vertical?alignment,?from?top?to?bottom
          ????????Axis:?layout.Vertical,
          ????????//?Empty?space?is?left?at?the?start,?i.e.?at?the?top
          ????????Spacing:?layout.SpaceStart,
          ????}.Layout(gtx,
          ????????layout.Rigid(
          ????????????func(gtx?C)?D?{
          ????????????????//?1、使用?layout.Inset?定義邊距
          ????????????????margins?:=?layout.Inset{
          ????????????????????Top:????unit.Dp(25),
          ????????????????????Bottom:?unit.Dp(25),
          ????????????????????Right:??unit.Dp(35),
          ????????????????????Left:???unit.Dp(35),
          ????????????????}
          ????????????????//?2、布局這些邊距
          ????????????????return?margins.Layout(gtx,
          ????????????????????//?3、在這些邊距內(nèi)創(chuàng)建按鈕
          ????????????????????func(gtx?C)?D?{
          ????????????????????????btn?:=?material.Button(th,?&startButton,?"Start")
          ????????????????????????return?btn.Layout(gtx)
          ????????????????????},
          ????????????????)
          ????????????},
          ????????),
          ????)
          ????e.Frame(gtx.Ops)


          推薦閱讀


          福利

          我為大家整理了一份從入門到進(jìn)階的Go學(xué)習(xí)資料禮包,包含學(xué)習(xí)建議:入門看什么,進(jìn)階看什么。關(guān)注公眾號 「polarisxu」,回復(fù)?ebook?獲取;還可以回復(fù)「進(jìn)群」,和數(shù)萬 Gopher 交流學(xué)習(xí)。

          瀏覽 107
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  九九九九在线视频播放 | 精品少妇人妻AV无码专区在线 | 国产男女日bb的视频 | 日韩熟妇无码 | 国产精品国产三级国产在线观看 |