1

I'm having weird issues with ScrollView that contains a relativeLayout with topMargin

<ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="beforeDescendants" android:fillViewport="true" android:focusableInTouchMode="true"> <RelativeLayout android:id="@+id/cp_editor_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:layout_marginTop="270dp" > ... 

This code example does not work. the scrolling stops after around 20px. If i'm removing the margin_top attribute then the scrolling works as expected.

Thanks for your help

1 Answer 1

4

I do not understand the issue with the topMargin stopping the scrolling. However, to achieve the desired margin and maintain the scrolling functionality i can think of two solutions:

1) add an extraneous View that has the same height as the margin you want, and put it above your Relative Layout (cp_editor_layout). It would look like this:

<ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="beforeDescendants" android:fillViewport="true" android:focusableInTouchMode="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="270dp" /> <RelativeLayout android:id="@+id/cp_editor_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" > </RelativeLayout> </LinearLayout> 

2) give the margin top margin to your scroll view since that space is unnecessary to have in the scroll anyway. If your going for some type of overscroll you need to subclass the ScrollView.

Hope this helps you somehow :)

Sign up to request clarification or add additional context in comments.

3 Comments

Well your first solution (adding a View) is actually what i did. your second solution didn't work because of overscrolling. There are ways to hack this problem. what i'm looking for is why is it even a problem. But thanks for your help
Btw your solution doesn't work. you have to wrap View and Relative in a LinerLayout or some other layout because SCrollView can have only one child. Also i want to add that this solution adds tons of unwanted complexity..now i have depth of 4 layouts
Right you are another wrapper is needed. I agree this isn't the most elegant of solutions, but it does work at least. Sorry I cannot be of more assistance.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.