2015-03-25 150 views
0

我有一個活動,其中包含一個滾動視圖,並有一個兩個孩子,但是當活動加載它不顯示頂部的部分,並從gridview頂部開始!android scrollview不顯示佈局的頂部

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/activityBackground" 
tools:context="com.test.app.fragment.HomeFragment"> 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="60dp" 
      android:background="@color/ColorPrimaryDark"/> 

     <com.test.app.util.ExpandableHeightGridView 
      android:id="@+id/homeNormalGridView" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:numColumns="2" 
      android:padding="5dp" 
      android:stretchMode="columnWidth" /> 
     </LinearLayout> 


</ScrollView> 

<fr.castorflex.android.circularprogressbar.CircularProgressBar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/homeProgress" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:indeterminate="true" 
    app:cpb_color="@color/ColorPrimary" 
    app:cpb_max_sweep_angle="300" 
    app:cpb_min_sweep_angle="10" 
    app:cpb_rotation_speed="1.0" 
    app:cpb_stroke_width="4dp" 
    app:cpb_sweep_speed="1.0" /> 
</RelativeLayout> 

,你看,我有GridView和RelativeLayout的滾動型作爲一個孩子,但我沒有任何想法,爲什麼RelativeLayout的是要躲起來!

+0

你能給我們一些截圖,讓我們更好地理解它嗎? – 2015-03-25 01:13:50

+0

@nayoso它只是從gridview頂部開始,我必須向上滾動才能看到relativelayout! – user2549089 2015-03-25 01:17:06

+0

但是在你向上滾動之後,你可以看到它,還是會反彈回來?相對佈局是否在操作欄之下? – 2015-03-25 01:18:38

回答

0

我的佈局中看不到任何東西會出現在您的自定義GridView上方。另外,您不在相對佈局上設置任何屬性來定位子項。

通常當使用類似ExpandableHeightGridView的東西時,它被用來允許在滾動視圖內嵌入網格視圖,禁用網格視圖滾動。這允許其他組件隨GridView一起滾動。我已經在項目中使用它來擁有同步的滾動條和快速返回滾動條。在這些原因中,網格視圖上方或下方通常會有一個所謂的錨定視圖,以允許在其中添加其他視圖。

<View 
     android:id="@+id/anchor" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp"/> 

在自定義代碼爲ExpandableHeightGridView你會附加其他視圖作爲錨來看,也許你的進度條,它會出現在地方的錨。定製gridview的java代碼也負責動態定位錨點。

如前所述,禁用gridView的滾動有一些缺點,它會刪除所有的優化,併成爲一個大表。如果表中有很多項目,您可能會看到性能問題或高內存使用情況。