自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Go Gio 實(shí)戰(zhàn):煮蛋計(jì)時(shí)器的實(shí)現(xiàn)之帶邊距的按鈕

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

[[439057]]

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

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

Button with margin

02 關(guān)鍵代碼

  • 為了突出結(jié)構(gòu),主要關(guān)注下面關(guān)鍵點(diǎn):
  • 使用 layout.Inset 定義邊距
  • 布局這些邊距

在這些邊距內(nèi)創(chuàng)建按鈕

代碼如下:

  1. layout.Flex{ 
  2.     // ... 
  3. }.Layout(gtx,  
  4.     layout.Rigid( 
  5.         func(gtx C) D { 
  6.             // 1、使用 layout.Inset 定義邊距 
  7.             margin := layout.Inset{ 
  8.                 // ... 
  9.             } 
  10.  
  11.             // 2、布局這些邊距 
  12.             margins.Layout( 
  13.                  
  14.                 // 3、在這些邊距內(nèi)創(chuàng)建按鈕 
  15.                 func(gtx C) D { 
  16.                     btn := material.Button(th, &startButton, "Start"
  17.                     return btn.Layout(gtx) 
  18.                 }, 
  19.              
  20.             ) 
  21.  
  22.             } 
  23.         } 
  24.     )     

03 代碼詳解

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

Button inside inset

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

  1. margins := layout.Inset{ 
  2.     Top:    unit.Dp(25), 
  3.     Bottom: unit.Dp(25), 
  4.     Right:  unit.Dp(35), 
  5.     Left:   unit.Dp(35), 

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

04 完整代碼

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

  1. case system.FrameEvent: 
  2.     gtx := layout.NewContext(&ops, e) 
  3.     // Let's try out the flexbox layout concept 
  4.     layout.Flex{ 
  5.         // Vertical alignment, from top to bottom 
  6.         Axis: layout.Vertical, 
  7.         // Empty space is left at the start, i.e. at the top 
  8.         Spacing: layout.SpaceStart, 
  9.     }.Layout(gtx, 
  10.         layout.Rigid( 
  11.             func(gtx C) D { 
  12.                 // 1、使用 layout.Inset 定義邊距 
  13.                 margins := layout.Inset{ 
  14.                     Top:    unit.Dp(25), 
  15.                     Bottom: unit.Dp(25), 
  16.                     Right:  unit.Dp(35), 
  17.                     Left:   unit.Dp(35), 
  18.                 } 
  19.                 // 2、布局這些邊距 
  20.                 return margins.Layout(gtx, 
  21.                     // 3、在這些邊距內(nèi)創(chuàng)建按鈕 
  22.                     func(gtx C) D { 
  23.                         btn := material.Button(th, &startButton, "Start"
  24.                         return btn.Layout(gtx) 
  25.                     }, 
  26.                 ) 
  27.             }, 
  28.         ), 
  29.     ) 
  30.     e.Frame(gtx.Ops) 

 

責(zé)任編輯:武曉燕 來源: 幽鬼
相關(guān)推薦

2021-11-26 00:04:20

Go計(jì)時(shí)器重構(gòu)

2019-12-24 16:52:22

Go語言騰訊TM函數(shù)

2013-05-23 16:01:47

Android開發(fā)移動(dòng)開發(fā)Chronometer

2021-03-26 09:10:11

Go 參透計(jì)時(shí)器

2023-04-17 09:08:27

CSS計(jì)時(shí)器

2011-05-31 16:50:35

Android 線程

2012-05-08 13:58:37

SharePoint

2020-03-10 09:42:04

JavaScript前端線程

2023-01-11 09:02:50

2011-09-08 14:01:01

Android Wid實(shí)例

2013-03-25 10:03:35

網(wǎng)絡(luò)優(yōu)化網(wǎng)絡(luò)抑制快速認(rèn)知網(wǎng)絡(luò)

2020-06-11 08:48:49

JavaScript開發(fā)技術(shù)

2022-06-28 15:29:56

Python編程語言計(jì)時(shí)器

2023-12-11 09:50:35

Linux定時(shí)器

2024-07-18 08:46:58

.NET輕量級(jí)計(jì)時(shí)器測(cè)量代碼塊

2010-01-05 15:00:30

.NET Framew

2010-01-25 11:29:33

Android計(jì)時(shí)器

2022-06-23 07:23:34

自定義組件計(jì)時(shí)器

2011-04-15 09:29:20

jQueryFlash

2022-06-30 16:10:26

Python計(jì)時(shí)器裝飾器
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)