2016-09-29 76 views
0

我剛開始學習Kivy,並與元素大小混淆。比方說,我想創建視頻播放器時間欄,中間有進度條,兩側有時間標籤。與Kivy中的元素大小混淆

我走到這一步:

<[email protected]>: 
    width: 100 
    padding: 10, 0 
    font_size: '14sp' 


<Player>: 
    BoxLayout: 
     orientation: 'horizontal' 
     pos: 0, 0 
     size: root.width, 40 

     canvas: 
      Color: 
       rgba: 0, 0.5, 0, 0.8 
      Rectangle: 
       pos: self.pos 
       size: self.size 

     TimeLabel: 
      size_hint: None, 1 
      text: "0" 

     ProgressBar: 
      value_normalized: 0.5 

     TimeLabel: 
      size_hint: None, 1 
      text: "10:00:00" 

在Windows上的一切似乎是確定:

enter image description here

在我的Galaxy S4雖然不是:

enter image description here

正如你在上一個截圖中看到的那樣o很低,進度條進入時間標籤。因爲我可以增加酒吧的高度和標籤的寬度,但在這種情況下,這一切都將在Windows上太大。

如何在Android上修復尺寸以在Windows上保存當前比例?

回答

4

永遠不要爲你的小部件使用默認的像素大小,就像你在幾個地方做過的一樣。使用任意大小提示或dp單位。這樣,你的用戶界面在任何地方看起來都一樣。更多信息here