2016-03-15 56 views
1

我想在頁眉和頁腳之間居中放置一個ScrollView。具體來說,我有一個ImageView必須在頂部,一個RelativeView在底部和一個ScrollView在兩者之間居中。當ScrollView的內容不大於頁腳和頁眉之間的空間時,我希望它像下圖中那樣垂直居中。我目前的嘗試將scrollview放在正確的位置,但是當內容小於可用空間時,它不會垂直居中。Android:在頁眉和頁腳之間居中滾動查看

Layout Pic

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:acg="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView 
    android:id="@+id/preloginLogo" 
    android:layout_width="350dp" 
    android:layout_height="130dp" 
    android:src="@drawable/logo" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentTop="true"/> 

<ScrollView 
    android:layout_width="@dimen/prelogin_main_content_width" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_below="@+id/preloginLogo" 
    android:layout_above="@+id/preloginTertiaryLinks"> 

    <RelativeLayout 
     android:id="@+id/mainContent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content">   

    </RelativeLayout> 
</ScrollView> 

<RelativeLayout 
    android:id="@+id/preloginTertiaryLinks" 
    android:layout_width="match_parent" 
    android:layout_height="96dp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:paddingTop="5dp"> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dip" 
     android:background="@color/lt_gray" 
     android:layout_centerVertical="true" 
     android:layout_alignParentTop="true"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true"> 

     <Button 
      android:id="@+id/prelogin_guestButton" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Footer"/> 
    </LinearLayout> 
</RelativeLayout> 

回答

1

你可以給頂部的ScrollView填充,並在底部。

<ScrollView 
    android:layout_width="@dimen/prelogin_main_content_width" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_below="@+id/preloginLogo" 
    android:layout_paddingTop="12dp" 
    android:layout_paddingBottom="12dp" 
    android:layout_above="@+id/preloginTertiaryLinks"> 

    <RelativeLayout 
     android:id="@+id/mainContent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content">   
    </RelativeLayout> 
</ScrollView> 
+0

太棒了,謝謝,這正是我一直在尋找的! – Le2e410

1

如何:

1:失去的上方和下方

2:設置邊界,這樣的頁眉和頁腳沒有得到覆蓋。

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_marginTop="130dp" 
     android:layout_marginBottom="96dp" 
     android:background="@color/red_danger" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     > 

    <RelativeLayout 
      android:id="@+id/mainContent" 
      android:layout_width="match_parent" 
      android:layout_height="100dp"> 

    </RelativeLayout> 
</ScrollView> 
相關問題