无法对齐可滚动标签中的文本

时间:2018-08-22 14:16:33

标签: python kivy kivy-language

我想制作一个可滚动的聊天面板,其文本从底部开始,但是当size_hint_y设置为None时,似乎我们无法将文本从底部对齐,并且文本从顶部开始。

这是我的可滚动标签:

ScrollView:
  canvas.before:
    Color:
      rgb:0,0,1/20.0,1
    Rectangle:
      size:self.size
      pos:self.pos
  Label:
    line_height:1
    spacing:3
    markup:True
    size_hint_y: None
    height: self.texture_size[1]
    width: self.width
    text: root.manager.chatLog
    halign:"left"
    valign:"bottom"
    text_size: self.width, None
    font_size:sp(25)
    font_name: "Odin Rounded - Bold.otf"

1 个答案:

答案 0 :(得分:0)

很显然,您可能想顺序地将文本行添加到滚动视图。 ScrollView仅接受1个小部件。因此,您必须指定一个布局。例如,在您的kv部分中,您可以具有以下内容:

BoxLayout:
    orientation: 'vertical'
    size_hint: 1,1
    ScrollView:
        GridLayout:
            id: chat_logs
            cols: 1
            padding: dp(8)
            spacing: dp(4)
            row_default_height: dp(14)

然后在您的python部分中:

chattext = "the chat line you received or want to send"
chatmess = Label(text=chattext, markup=True, height=dp(12), size_hint=(1,None))
self.chat_logs.add_widget(chatmess)