2015-03-25 152 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的滚动有一些缺点,它会删除所有的优化,并成为一个大表。如果表中有很多项目,您可能会看到性能问题或高内存使用情况。