Skip to content
Advertisement

Kivy Scrollview with FloatLayout Is Positioning itself at the bottom of the screen

In summary, the program takes a bunch of list data and populates a row to describe a task with some actions attached to it.

After much work I got scrollview working with Floatlayout somewhat. The issue is that the list of rows of labels are stuck at the bottom part of the screen as in the screenshot. When you run the code, put your curser towards the very bottom of the screen and scrolldown. The widgets will appear and it scrolls (yay). You will then have experienced my two problems

  1. Why do the widgets start outside of view
  2. Why is the layout stuck at the bottom.

I am looking at how to make that floatlayout be 12/15 from the top of the screen, and for the widgets to be in frame from start.

enter image description here

JavaScript

Advertisement

Answer

Your questions:

  1. The widgets are outside the initial view because you are positioning the widgets using pos_hint of {'y': 12/15} to start. That sets the largest y pos_hint at 0.8, and you decrease it from there. So the layout above 0.8 is empty. Also, your ScrollView has size_hint set to None for y. That causes the default value of 100 to be used as its height, so only the top 100 pixels of the layout can fit.
  2. The default pos for wigets is [0,0]. Since you don’t set the position of the ScrollView, it will get the default pos.

I suggest using a Layout that will do a lot of the work for you. Perhaps a GridLayout. And you can define the look of the MainScreen using kv. Here is a kv that does that:

JavaScript

If you load the above kv before creating the MainScreen(), then you can simplify your py code for the MainScreen class:

JavaScript

Note that all the position information is removed from the created Buttons and Labels, since the GridLayout handles that.

Another thing to note is that you are using on_enter() to trigger the widget drawing. That will get triggered every time you enter the MainScreen, so I have added a widgets_drawn attribute to avoid adding the same widgets every time the MainScreen is entered.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement