https://kotlinlang.org logo
#android
Title
# android
a

Alexanderkvamme

03/17/2020, 12:57 PM
Guys can anyone give me some advice? I got this screen. The green and white part is a recyclerview with its height set to WRAP_CONTENT. The entire recyclerview is constrained to all edges of the screen, and yet, as you can see, it is centered, with its content being wrapped... What i would expect is the content to be positioned from the top, not from the center. IS there a way to do this?
a

Araib

03/17/2020, 1:05 PM
Remove wrap content and set height to 0dp. Constraints will take care of it
👌 5
a

Alexanderkvamme

03/17/2020, 1:19 PM
Ohh my shit it actually worked! 😄 Can you explain what happens so i can remember it? 🙂
a

Araib

03/17/2020, 1:21 PM
When you set it to wrap content the RecyclerView takes as much space as the views within and then the constraints apply on top of it to make it center. If you don't apply wrap content and use 0dp then the RecyclerView takes as much space as the constraints provide it.
To better see this visually, try setting background to RecyclerView and see what it does in wrap content and what it does with 0dp.
2 Views