2

I have a very weird issue with a FrameLayout holding a ScrollView. My layout looks like the following:

<FrameLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   <ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:layout_marginTop="50dp">
      <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:orientation="vertical">
     </LinearLayout>
   </ScrollView>

   <...
   />
</FrameLayout>

The issue that I have is with the: layout_marginTop attribute on the ScrollViewtag. It doesn't apply the same way accross different devices. For instance, on a Nexus S (running ICS) it is interpreted correctly by adding some space at the of the screen, but on another (Galaxy S2 running Gingerbread) it creates space at the bottom of the screen rather than the top of screen.

Any idea?

Thanks!

[EDIT]

  • It seems that the problem is common to all devices running an Android version lower than 3.0.

  • Thanks for noticing those non-sense extra attributes, it appears they were here because that FrameLayout used to be wrapped inside LinearLayout before.

Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
  • Layout can be tricky. FrameLayout doesn't have an 'orientation' attribute, and unless it's the child of a LinearLayout that layout_gravity attribute will also have no effect. I suggest using some solid background colours to see whats actually going on... I suspect it's not what you think. – Reuben Scratton Feb 20 '12 at 10:42
  • @ReubenScratton It's actually the child of another `FrameLayout` (should have mentioned it). I removed all those extra attributes as you suggested. Will try using solid background colours to see what's going on. Thanks. – Amokrane Chentir Feb 20 '12 at 10:59

3 Answers3

2

No use android:layout_gravity="center_vertical" with android:layout_width="match_parent". This is no sense.

Try to use android:paddingTop="50dp" in FrameLayout instead of android:layout_marginTop="50dp" in ScrollView

<FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="50dp">
    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                >
        </LinearLayout>
    </ScrollView>
Oleksii Masnyi
  • 2,922
  • 2
  • 22
  • 27
  • Aren't `fill_parent` and `match_parent`exactly the same thing? I removed all the extra attributes. Will try adding a paddingTop at the `FrameLayout`, thanks! – Amokrane Chentir Feb 20 '12 at 11:16
  • They are [identical](http://stackoverflow.com/questions/5761960/what-is-the-difference-between-match-parent-and-fill-parent-property-in-android) – Oleksii Masnyi Feb 20 '12 at 12:15
1

try android:fillViewPort=true

josephus
  • 8,284
  • 1
  • 37
  • 57
1

Fixed it by using android:paddingTop on the ScrollViewinstead of android:layout_marginTop.

<FrameLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   <ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:layout_paddingTop="50dp">
      <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:orientation="vertical">
     </LinearLayout>
   </ScrollView>

   <...
   />
</FrameLayout>
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158