pretty

Wednesday 24 July 2019

Android ScrollView child width is larger than the screen (Api 21 bug)


On Android Lollipop this layout would produce a screen where children views of the ScrollView would have incorrect width.

This is how the view looks on api level 21 emulator


And this the correct result, from api 27


To fix this ScrollView issue on api 21 devices, the child view "android:layout_margin" should be replaced with "android:padding". If it is not acceptable for the layout to have padding instead of margin (for example due to background color or click area placement) - padding can be set on parent container views. rows="20"