【发布时间】:2021-05-28 10:29:08
【问题描述】:
我在下面有这段代码 - 正在开发某种在线流媒体应用程序。
我的目标是让recycler view 项目占据 90%,而我的顶部导航占据 10%。
我所做的是将两者都放在box layout 中,但recycler view 项目似乎消失了。我没有收到错误,只是在应该显示 recycler view 项目的地方出现了一个空白屏幕。
我做错了什么 谢谢你的帮助
py
import os
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.list import OneLineListItem, OneLineRightIconListItem, OneLineAvatarIconListItem, OneLineAvatarListItem, IRightBodyTouch
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.button import MDFlatButton, MDRectangleFlatButton, MDRaisedButton
from kivymd.uix.boxlayout import MDBoxLayout
from kivy.uix.recycleview import RecycleView
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.screen import MDScreen
from kivy.properties import StringProperty
from pathlib import Path, PurePath
# Music Path
storageLocation = Path.cwd()
if Path('Books').is_dir():
storageLocation = Path.cwd() / 'Books'
# Check if file is in SD card
# elif Path.is_mount():
else:
storageLocation = Path.cwd() / 'Books'
storageLocation.mkdir()
class RecycleViewRow(BoxLayout):
text = StringProperty()
class MainScreen(MDScreen):
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
booksdir = [f for f in storageLocation.iterdir() if f.is_dir()]
self.children[0].data = [{'text': str(x), 'id': str(x)} for x in booksdir]
self.theFiles = [self.children[0].data]
return
class Playlist(MDScreen):
def on_enter(self, *args):
return
class Main(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
sm = ScreenManager()
sm.add_widget(MainScreen(name='MainScreen'))
sm.add_widget(Playlist(name='Playlist'))
sm.add_widget(Test(name="Test"))
return sm
def fill_playlist(self, dir):
self.root.current = 'Playlist' # this also clears the play list
playlist = self.root.get_screen('Playlist')
for sub in os.listdir(dir):
playlist.ids.Box.add_widget(OneLineAvatarIconListItem(text=sub))
基维
<RecycleViewRow>:
orientation: 'vertical'
OneLineAvatarIconListItem:
text: root.text
#on_press: app.root.message_box(root.text)
#on_release:app.root.current = 'Playlist'
on_release: app.fill_playlist(root.text)
Container:
id: container
MDIconButton:
icon: "download"
<MainScreen>:
MDBoxLayout
orientation:'horizontal'
MDToolbar:
title: 'Books'
left_action_items: [['menu', lambda x: x]]
right_action_items: [['dots-vertical', lambda x: x]]
MDBoxLayout
RecycleView:
id: rv
viewclass: 'RecycleViewRow'
spacing: 40
padding:10, 10
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
<Playlist>
MDBoxLayout:
orientation:'vertical'
spacing: 5
size_hint_y: None
height: self.minimum_height
MDList:
id:Box
【问题讨论】:
标签: python-3.x android-recyclerview kivy kivymd