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
.
The RelativeLayout
is similar to the FloatLayout;
thus, to spot the difference, it is advisable to go through the Using FloatLayout recipe.
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 KV file.Set size and position for the layout.
As shown here, define a subclass of
FloatLayout
and add theRelativeLayout
as a child.import kivy from kivy.app import App...