android scrollview没有显示布局的顶部

时间:2015-03-25 01:04:50

标签: android scrollview

我有一个包含滚动视图且有两个孩子的活动,但是当活动加载时,它不会显示顶部并从gridview的顶部开始!

<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作为scrollview的孩子,但我不知道为什么relativeLayout会隐藏!

1 个答案:

答案 0 :(得分:0)

我的布局中没有看到任何显示在自定义GridView上方的内容。此外,您没有在相对布局上设置任何属性来定位子项。

通常在使用ExpandableHeightGridView之类的东西时,它用于允许在滚动视图中嵌入网格视图,禁用网格视图滚动。这允许其他组件与GridView一起滚动。我已经在项目中使用它来拥有同步滚动条和快速返回滚动条。在这些原因中,通常在网格视图的上方或下方有一个所谓的锚视图,以允许其他视图附加在那里。

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

在ExpandableHeightGridView的自定义代码中,您将附加另一个视图作为锚视图,可能是您的进度条,它将显示在锚点的位置。自定义gridview的java代码也负责动态定位锚点。

如上所述,禁用gridView的滚动有一些缺点,它会删除所有优化并成为一个大表。如果表中有大量项目,您可能会看到性能问题或高内存使用情况。

相关问题