2

I'm working with KivyMD. The UI is so slow. Animations are so slow and often stuck. Even in the Kitchen Sink example. Although it's fine on my Windows and Linux. The problem is after building package for android.

This is exactly my question and the answer given by developer:

https://github.com/HeaTTheatR/KivyMD/issues/77

Unfortunately it didn't help and UI is slow

main.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.properties import StringProperty

from kivymd.theming import ThemeManager
from kivymd.utils.cropimage import crop_image
from kivymd.tabs import MDTabs,MDTabsBase
from kivymd.button import MDTextButton

class Scr_Mng(ScreenManager):
    pass

################################ 

class MainPage(Screen):

    def __init__(self, **kwargs):
        super(MainPage, self).__init__(**kwargs)
        Window_width, window_height = Window.size
        background_size = (int(Window_width),int(window_height))
        #crop_image(background_size , "bg.jpg" , "bg_croped.jpg"  )


##############################
class Ask_tab(MDTabsBase):
    profile_pic = StringProperty('assets/bg.jpg')
    profile_name = StringProperty('Sina')
    def new_question(self,question):
        print(question)
##############################
class Answer_tab(MDTabsBase):
    def load_questions(self):
        for x in range(20):
            self.ids.question_items_box.add_widget( Question_items() )

##############################

class Question_items(BoxLayout):
    pass

##############################
class Me_tab(MDTabsBase):
    pass
##############################

class Myapp(App):
    theme_cls = ThemeManager()
    theme_cls.primary_palette = 'DeepPurple'
    title = "Navigation Drawer"
    theme_cls.theme_style = "Light"
    mainpage_title = "Ask/Answer"

    def build(self):
        return Scr_Mng()


Myapp().run()

kv file:

#:import MDToolbar kivymd.toolbar.MDToolbar
#:import MDTabs kivymd.tabs.MDTabs
#:import MDLabel kivymd.label.MDLabel
#:import MDTextField kivymd.textfields.MDTextField
#:import MDTextFieldRound kivymd.textfields.MDTextFieldRound
#:import MDRoundFlatButton kivymd.button.MDRoundFlatButton

#:import MDCard kivymd.cards.MDCard  

<Scr_Mng>:
    MainPage:

<Ask_tab>:
    text: 'Ask'
    FloatLayout:
        size: root.width, root.height
        ScrollView:
            BoxLayout:
                orientation: 'vertical'
                size_hint_y: None
                height: self.minimum_height
                padding: dp(48)
                spacing: dp(15)

                BoxLayout:
                    size_hint: None,None
                    size: root.width*0.2,root.width*0.2
                    pos_hint: {'center_x': .5}
                    canvas.before:
                        Color:
                            rgba: 1,1,1,1
                        Ellipse:
                            pos: self.pos
                            size: self.size
                            source: 'assets/unknown.jpg'

                MDLabel:
                    pos_hint: {'center_x': .5 }
                    size_hint: 1, None
                    height: root.width*0.1
                    text: root.profile_name
                    text_size: self.size
                    halign: 'center'
                    font_style: 'H6'   

                MDTextField:
                    id: question_field
                    pos_hint: {'center_x': .5 }
                    size_hint_x: 0.8
                    multiline: True
                    hint_text: "What question is in your mind?"
                    helper_text: ""
                    helper_text_mode: "persistent"
                    max_text_length: 1000
                MDRoundFlatButton:
                    text: "Post"
                    icon: "login"
                    pos_hint: {'center_x': .5}
                    width: 170
                    on_release: root.new_question(question_field.text)


<Answer_tab>:
    text: 'Answer'
    on_kv_post: root.load_questions()
    FloatLayout:
        size: root.width, root.height
        ScrollView:
            BoxLayout:
                id: question_items_box
                orientation: 'vertical'
                size_hint_y: None
                height: self.minimum_height
                padding: dp(15)
                spacing: dp(15)

<Question_items>:
    orientation: 'vertical'
    spacing: dp(15)
    size_hint: 1,None
    height: 300
    pos_hint: {'center_x': .5}
    BoxLayout:
        canvas.before:
            Color:
                rgba: 0.3,0.5,0.2,1
            Rectangle:
                pos: self.pos
                size: self.size
    MDSeparator:


<Me_tab>:
    text: 'Me'

<MainPage>:
    name: 'main'
    # on_kv_post: root.load_main_tabs() 
    BoxLayout:
        orientation: 'vertical'
        MDToolbar:
            id: toolbar
            title: app.mainpage_title
            md_bg_color: app.theme_cls.primary_color
            background_palette: 'Primary'
            background_hue: '500'
            elevation: 10
            right_action_items:
                [['dots-vertical', lambda x: None]]

        MDTabs:
            id: main_tabs
            Ask_tab:
            Answer_tab:
            Me_tab:
ArtemSBulgakov
  • 973
  • 10
  • 21
Sina
  • 21
  • 4
  • 1
    i might be misunderstanding, but if the developer of the library was not able to help you with your problem, I doubt anyone here will be able to – a_local_nobody Aug 16 '19 at 13:19
  • It looks like Sina is asking about optimizing the build process. The linked [bug #77](https://github.com/HeaTTheatR/KivyMD/issues/77) says the "application UI [in my build] looks slow [but] I install KIvyMD Demo from Google Play and it works fine." – bitinerant May 06 '20 at 09:50

1 Answers1

0

There are a few things you should do to solve the issue:

  1. Make sure the icon of the app is not too large, for example, if the icon is a 1200x1800 image (png, jpg, etc) that will make the apk to lag before you install it, during you install it, and when you attempt to start the app, even if the icon is 200x300 it may also cause lagging (this has to be setup in your "buildozer.spec" file), for example mine is:

    (str) Presplash of the application

    presplash.filename = /home/jbsidis/Escritorio/_a/Suministros/fs.png

    (str) Icon of the application

    icon.filename = /home/jbsidis/Escritorio/_a/Suministros/fs_icon.png

  2. Sometimes the current standard version of p4a, kivy and kivyMD are used, to make sure you have the latest but stable versions of everything, I recommend the following in the requirements of your spec file (doing this will generate a fluent app like this one https://youtu.be/WxsL1pdzpYc ):

    requirements = kivy==2.0.0,kivymd,python3,pyjnius,plyer,requests,urllib3,chardet,idna,pip,Image,PIL

So recommended version of kivy is version 2.0.0 and recommended kivyMD is the current stable version (not master branch because icons do not work in that one)

Everything should be solved.

Just do the command in the terminal to create the apk:

python3 -m buildozer -v android debug

Or:

buildozer -v android debug