回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在制作一个网页垃圾,可以从不同的网站上获取文章。为此,我动态地将文章小部件添加到它们各自的GridLayouts中。然而,有些屏幕上的文章是均匀分布的,而另一些则是零星分布的。看起来文章越长,空间就越小。下面是我认为相关的代码片段(除了1300多行之外,我会包括所有内容)</p>
<p>示例:</p>
<p>好间距
<img src="https://i.stack.imgur.com/fNqcg.png" alt="Good spacing"/></p>
<p>间隔差
<img src="https://i.stack.imgur.com/doGGP.png" alt="Bad spacing"/></p>
<p>Python:</p>
<pre><code>def text_collision(self):
labels = [i for i in self.news_articles.children]
for label in labels:
font_instance = 35
label.size = label.texture_size
if label.collide_point(*label.to_widget(*Window.mouse_pos)):
animation = Animation(font_size=font_instance + 2, s=1 / 60, duration=.06)
label.color = (.96, .60, .61, 1)
if label.count == 0:
animation.start(label)
label.count += 1
else:
label.count = 0
Animation.cancel_all(label)
label.color = (1, 1, 1, 1)
label.font_size = font_instance
def articles(self):
titles = self.csv_load()[0]
links = self.csv_load()[1]
for lnk, items in zip(links, titles):
if len(items.strip()) == 0 or len(lnk.strip()) == 0:
continue
article_widget = Label(text="[ref={}][b]{}[/b][/ref]".format(lnk, items), markup=True,
font_size=35, text_size=(700, None), halign='left', size_hint_y=None)
self.news_articles.add_widget(article_widget)
article_widget.on_ref_press = self.openlink
</code></pre>
<p>基维:</p>
<pre><code>ScrollView:
do_scroll_x: False
do_scroll_y: True
pos: (50, -140)
smooth_scroll_end: 5
GridLayout:
id: articles
cols: 1
col_default_width: 700
padding: [0, 140, 0, 0]
size_hint_y: None
height: self.minimum_height
spacing: 150
</code></pre>