簡體   English   中英

ScrollView內FrameLayout布局邊距的問題

[英]ScrollView inside FrameLayout layout margin's issue

我有一個非常怪異的問題,與持有ScrollViewFrameLayout 我的布局如下所示:

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

我遇到的問題是ScrollView標記上的layout_marginTop屬性。 它在不同設備上的應用方式不同。 例如,在Nexus S(運行ICS)上,可以通過在屏幕的上添加一些空間來正確地解釋它,但是在另一台(運行Gingerbread的Galaxy S2)上,它可以在屏幕的底部而不是在屏幕的頂部創建空間。

任何想法?

謝謝!

[編輯]

  • 似乎該問題對於運行低於3.0的Android版本的所有設備都是常見的。

  • 感謝您注意到這些無用的額外屬性,它們出現在這里是因為以前FrameLayout以前被包裝在LinearLayout

請勿將android:layout_gravity="center_vertical"android:layout_width="match_parent" 這是沒有道理的。

嘗試在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

通過使用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