13

I have an android layout_file that looks something like the following

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/post_ride_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_margin"
        android:padding="@dimen/activity_margin"
        android:background="@drawable/google_now_style_card"
        android:orientation="vertical" >

    ...

    </LinearLayout
</ScrollView

@dimen/activity_margin is 16dp

When I'm running the app, I am unable to scroll to the bottom of the entire layout, as in, it won't display the bottom margin. This picture clarifies

enter image description here

Note that the hint that the bottom of the layout has been reached (the glow from the bottom), yet the scrollbar on the right indicates that there is more to scroll down to.

What I expect to happen is to be able to see the margin at the bottom, just like the margins at the side of the layout.

rperryng
  • 3,233
  • 3
  • 22
  • 35

4 Answers4

8

Try setting

android:fillViewport="true"

in your ScrollView. It will give it full height and then you can apply bottom margin.

VipulKumar
  • 2,385
  • 1
  • 22
  • 28
  • Can applying margin to ScrollView work for you? I mean it's the same thing and if it is doable for your layout, it'll be easy. ScrollView wraps height of child element around the content so i don't think there will be a way to leave margin to child element. Instead, you can apply margin to your ScrollView and wrap it around your LinearLayout. – VipulKumar Apr 05 '14 at 17:45
  • If I apply the margin to the scrollview that spacing will always be there regardless if I am at the bottom of the linearLayout or not. – rperryng Apr 05 '14 at 17:46
  • I checked. First option is working for me. The layout is having bottom margin after the scroll is finished. My layout is – VipulKumar Apr 05 '14 at 17:54
  • I copied your exact code and it's showing bottom margin. – VipulKumar Apr 05 '14 at 18:07
  • Alright alright let me give it a try sounds promising! – rperryng Apr 05 '14 at 18:09
  • I honestly have no idea what I'm doing wrong, here's a SCREENSHOT of a snippet of my layout file: http://i.gyazo.com/5aa379ce1a66a95d40b41235216020c4.png – rperryng Apr 05 '14 at 18:20
  • The problem might be in your inner Views under LinearLayout. Because i can clearly see margin here. I have uploaded your layout and a screenshot of layout. see here: https://www.dropbox.com/sh/mj2cq168uuyc24y/2OfvHOQqLm – VipulKumar Apr 06 '14 at 04:25
  • For some reason, wrapping the LinearLayout within a FrameLayout resolved the issue. While it is inefficient, this workaround will tide me over for now. If I ever find out any further details I will be sure to let you know – rperryng Apr 07 '14 at 00:34
7

I ran into the same problem. To solve, I used padding instead of margin and then I set android:fillViewport="true" for ScrollView. Anything goes well now!

inverted_index
  • 2,329
  • 21
  • 40
3

add android:clipToPadding="false" and android:paddingBottom="32dp" to LinearLayout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/post_ride_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_margin"
        android:background="@drawable/google_now_style_card"
        android:orientation="vertical"
        android:paddingBottom="32dp"
        android:clipToPadding="false">

    ...

    </LinearLayout
</ScrollView

this worked for ConstraintLayout.

also add android:fillViewport="true" to fill whole of height.

Mohammad cs
  • 191
  • 1
  • 10
1

It will work for child of child of scrollview. if you put one child under scrollview it wont consider bottom margin of child. but if you put child under child as shown in code it works fine.

    <ScrollView>
        <LinearLayout>
            <LinearLayout>
                ...
            </LinearLayout>
        </LinearLayout>
    </ScrollView>