2014-07-19 72 views
0

我怎樣才能插入一行(分隔符)部件之間的網格視圖,並在KV文件網格視圖也色邊框:插入線,和顏色邊框在KV文件

TextBox只是一個TextInput框與max_chars功能。

當前KV文件:

<[email protected]> 
    text_size: self.size 
    valign: 'middle' 

<ContactFrm> 
    padding: 5,5 
    orientation: 'vertical' 
    #row_default_height: '36dp' 
    #cols:1 
    #spacing: 0,0 

    GridLayout: 
     cols: 4  
     row_default_height: '32dp' 
     row_force_default: True 
     spacing: 10,0 
     size_hint_y: None 
     #height:34 

     Label: 
      text: 'Name' 
      size_hint_x: 0.5 

     TextBox: 
      id:name 
      max_chars:35 

     Label: 
      text: 'Contact Name' 
      size_hint_x: 0.5 

     TextBox: 
      id:contactname 
      max_chars:35 

    GridLayout: 
     cols: 4  
     row_default_height: '32dp' 
     row_force_default: True 
     spacing: 10,0  
     size_hint_y: None 
     #height: 36    

     Label: 
      text: 'Mobile 1' 
      size_hint_x: 0.5 
     TextBox: 
      id:mob1 
      max_chars:35 
     Label: 
      text: 'Mobile 2' 
      size_hint_x: 0.5 
     TextBox: 
      id:mob2 
      max_chars:35 
     Label: 
      text: 'Landline' 
      size_hint_x: 0.5 
     TextBox: 
      id:land1 
     max_chars:35 
    Label: 
     text: 'E-mail' 
     size_hint_x: 0.5 
    TextBox: 
     id:email1 
     max_chars:75 

GridLayout: 
    row_default_height: '32dp' 
    row_force_default: True 
    spacing: 10,0 
    cols: 4  
    size_hint_y: None 
    #height: 36 

    Label: 
     text: 'Street 1' 
     size_hint_x: 0.5 
    TextBox: 
     id:street1 
     max_chars:75 
    Label: 
     text: 'Street 2' 
     size_hint_x: 0.5 
    TextBox: 
     id:street2 
     max_chars:75 
    Label: 
     text: 'Area' 
     size_hint_x: 0.5 
    TextBox: 
     id:area 
     max_chars:75 
    Label: 
     text: 'City' 
     size_hint_x: 0.5 
    TextBox: 
     id:city 
     max_chars:35 
    Label: 
     text: 'District' 
     size_hint_x: 0.5 
    TextBox: 
     id:district 
     max_chars:35 
    Label: 
     text: 'State' 
     size_hint_x: 0.5 
    TextBox: 
     id:state 
     max_chars:35 
    Label: 
     text: 'Zip Code' 
     size_hint_x: 0.5 
    TextBox: 
     id:zipcode 
     max_chars:10 
BoxLayout: 

我是新來的Python和kivy,所以上面的代碼可能有點幼稚,請指教,所有我也可以提高。謝謝。

終極密碼我修改使用,所以厚度也可以提供:

<[email protected]>: 
    id: separator 
    size_hint_y: None 
    height: 6 
    thickness: 2 
    canvas: 
     Color: 
      rgb: .24, .65, .94 
     Rectangle: 
      #pos: 0, separator.center_y 
      pos: self.pos[0], separator.center_y 
      size: separator.width, self.thickness 
+0

我在Kivy是新的,但:你在文檔(或網絡)是否有插件,你可以作爲分隔符使用搜索? – furas

回答

2

我新的Kivy但我認爲你可以添加正常Widget作爲分隔符和畫布上繪製矩形。

像這樣的東西給我衝線 - 見下面的圖片:

Widget: 
     id: separator 
     size_hint_y: None 
     height: 6 
     canvas: 
      Color: 
       rgb: 1., 0., 0. 
      Rectangle: 
       pos: 0, separator.center_y 
       size: separator.width, 2 

enter image description here


我想你可以使用網格佈局畫布(或canvas.before)來繪製邊界(使用矩形或兩個 - 外部邊框顏色和內部背景顏色),但可能需要(以某種方式)製作一些邊距以顯示邊框。


編輯:

第一溶液與恆定的厚度。

對於不同的厚度,你需要一些計算。
我加了margin來做這個計算。

<[email protected]> 
    size_hint_y: None 
    thickness: 2 
    margin: 2 
    height: self.thickness + 2 * self.margin 
    color: 1., .0, .0 
    canvas: 
     Color: 
      rgb: self.color 
     Rectangle: 
      pos: self.x + self.margin, self.y + self.margin + 1 
      size: self.width - 2 * self.margin , self.thickness 

BTW:
pos使用+1因爲它看起來更好的(但我不知道爲什麼)。
我加左右邊距。

enter image description here

+0

這對分隔符有效,對於邊框我想我必須附加另一個小部件才能獲得效果。同樣對於間距問題,我用'pos:self.pos [0],separator.center_y' – surpavan

+0

替換了'pos:0,separator.center_y'我認爲你甚至可以使用'separator.x'或'self.x '代替'self.pos [0]'使其更具可讀性。 – furas

+0

鎬,謝謝,這是對我的更新。 – surpavan