我在一个聊天页面上有几个问题,我试图使chatbox的文本大小加上一个很小的空间,但是我在这样做时有问题,而且chatbox在屏幕外重叠,我希望日期标记直接在每个chatbox下面,但是我也在做这个问题。这是代码,下面是我当前情况的图片。我真的很感激你的帮助
def send_message(self, _):
app = App.get_running_app()
message = self.messagetextinput.text
if len(message) > 0:
database.child("messages").child(app.localId).update({self.localId: message})
self.chatbubble = Button( background_color = [0.082, 0.549, 0.984, 1.0], background_normal = "",
pos_hint= {"center_x": 1}, color = (1, 1, 1, 1), size_hint_y = None, halign = "left", valign = "middle", text_size = (290, 40), font_name = "fonts/Qanelas-Regular.otf" )
self.now = datetime.now()
self.dt_string = self.now.strftime("%H:%M:")
self.timestamp = Label(text = str(self.dt_string), pos_hint= {"center_x": 1}, color = (0, 0, 0, 1), size_hint = (.8, .1))
self.chatbubble.text = self.messagetextinput.text
self.ids.chatlayout.add_widget(self.chatbubble)
self.add_widget(self.timestamp)
self.ids.scrollview.scroll_to(self.chatbubble)
self.messagetextinput.text = ""
Clock.schedule_once(self.focus_text_input, 0.1)
def focus_text_input(self, _):
self.messagetextinput.focus = True

发布于 2020-03-02 14:09:55
用一堆关于文本长度的if语句来解决这个问题,取决于文本的长度,聊天气泡的大小会调整,而chatbox下没有显示时间的原因是我错误地将它添加到滚动视图中,而不是chatbox所在的框布局中。
https://stackoverflow.com/questions/60459854
复制相似问题