Using RelativeLayout
RelativeLayout is a self-contained layout where the positions are relative to the layout and not with the app window. In this recipe, we will localize two buttons in RelativeLayout
, which will be a child of FloatLayout
.
Getting ready
The RelativeLayout
is similar to the FloatLayout;
thus, to spot the difference, it is advisable to go through the Using FloatLayout recipe.
How to do it…
To complete the recipe, perform the following steps:
- In the KV file, define two buttons with different positions using the following code:
<MyW1>: Button: id: label1 size_hint: .2, .2 pos: 150, 150 text: 'B1' Button: id: label2 size_hint: .1, .1 pos: 30, 30 text: 'B2'
- In the Python file, define a class as a
RelativeLayout
reference for the rule of the ...
Get Kivy Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.