Button on a fixed position


I have created an object which is ‘draggable’ when the LV_EVENT_PRESSING event occurs.

On this parent object I have added 2 buttons as children. When I drag the parent object, the buttons are also dragged in the same direction. However I would like the buttons to remain at a fixed position (for example on the top of my screen).

Is there any way to do this ?

Thanks and regards

What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?

master (latest)


There’s multiple ways of doing this:

You could set the buttons as children of the top layer of the display, this will be on top of every screen you create as well:

See layer documentation: Layers — LVGL documentation

Or set the buttons as children of the currently active screen:

These two are the simplest but there’s a lot of ways to do it- however they both stop the button from being a child of this parent object you created.

I’ve not tested this but I believe it’s possible to give the buttons a position relative to the parent upon creation, without them moving along afterwards, try using lv_obj_align_to(), in testing earlier I found this stopped my children from moving with their parent which I why I never use it but it might be useful in this case: see Base object (lv_obj) — LVGL documentation