简体   繁体   English

ScrollView内FrameLayout布局边距的问题

[英]ScrollView inside FrameLayout layout margin's issue

I have a very weird issue with a FrameLayout holding a ScrollView . 我有一个非常怪异的问题,与持有ScrollViewFrameLayout 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 ScrollView tag. 我遇到的问题是ScrollView标记上的layout_marginTop属性。 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. 例如,在Nexus S(运行ICS)上,可以通过在屏幕的上添加一些空间来正确地解释它,但是在另一台(运行Gingerbread的Galaxy S2)上,它可以在屏幕的底部而不是在屏幕的顶部创建空间。

Any idea? 任何想法?

Thanks! 谢谢!

[EDIT] [编辑]

  • It seems that the problem is common to all devices running an Android version lower than 3.0. 似乎该问题对于运行低于3.0的Android版本的所有设备都是常见的。

  • Thanks for noticing those non-sense extra attributes, it appears they were here because that FrameLayout used to be wrapped inside LinearLayout before. 感谢您注意到这些无用的额外属性,它们出现在这里是因为以前FrameLayout以前被包装在LinearLayout

No use android:layout_gravity="center_vertical" with android:layout_width="match_parent" . 请勿将android:layout_gravity="center_vertical"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:paddingTop="50dp" ,而不是在ScrollView中使用android:layout_marginTop="50dp"

<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>

尝试android:fillViewPort=true

Fixed it by using android:paddingTop on the ScrollView instead of android:layout_marginTop . 通过使用ScrollView上的android:paddingTop而不是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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM