Trying to understand margins in LinearLayout inside a ScrollView
I digged a little bit into the source code:
ScrollView
extends FrameLayout
. This one has some margin issues itself and ScrollView
is not even trying to solve that. The margins are basically ignored while measuaring.
But in the end it doesn't matter since you should be able to define a padding on the ScrollView
itself (it's an affirmation, didn't try that). There should be no need for margin for a single child view.
Hello Knickedi and Ricardo Amaral,
Though this answer is marked as solved but I want to put some lights on the issue.
As Knickedi said, ScrollView extends FrameLayout.
So My answer is that You can set the layout_gravity
of LinearLayout within scrollView and then layout_margin
will work in LinearLayout as case with linearLayout within FrameLayout.
I had same issue and I've applied this and it worked for me. :)
Example :
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginTop="30dp" android:orientation="vertical" ></ScrollView>