如何在android的scrollView中添加gridView

如何在android的scrollView中添加gridView,android,gridview,android-scrollview,Android,Gridview,Android Scrollview,在将该问题作为可能的副本进行表决之前,或者我有一个材料设计导航抽屉。在主要活动中,我有以下元素,如图a和图B所示。我想添加一个scrollview功能,以便滚动项目将使用户能够滚动整个布局,包括图a所示的gridView。但是,在包括scrollview后,我在图B中遇到了问题其中只显示一行。我在谷歌和S/O上进行了研究,但解决方案不起作用。解决方案没有,可能您需要此自定义gridView 公共类InnerGridView扩展了GridView{ public InnerGridView(Con

在将该问题作为可能的副本进行表决之前,或者我有一个材料设计导航抽屉。在主要活动中,我有以下元素,如图a和图B所示。我想添加一个scrollview功能,以便滚动项目将使用户能够滚动整个布局,包括图a所示的gridView。但是,在包括scrollview后,我在图B中遇到了问题其中只显示一行。我在谷歌和S/O上进行了研究,但解决方案不起作用。解决方案没有
,可能您需要此自定义gridView

公共类InnerGridView扩展了GridView{

public InnerGridView(Context context) {
    super(context);
}

public InnerGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public InnerGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // Max Height
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
            MeasureSpec.AT_MOST);


    super.onMeasure(widthMeasureSpec, expandSpec);
}

}

我想我可以为任何其他来寻找完整答案的人添加这个选项。在实现@innershows answer之后,我创建了类InnerGridView,并在我的主要活动中引用了我的
onCreate()
,比如:
InnerGridView gridView=(InnerGridView)findViewById(R.id.grid);
adapter=新的CustomListAdapter(此,movieList);
setAdapter(适配器)
然后在我的活动中:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        tools:context="com.snappy.stevekamau.cosmeticsapp.MainActivity">

        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar"></include>


        <ImageView
            android:id="@+id/imageTop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_below="@+id/app_bar"

            android:layout_marginLeft="3dp"
            android:layout_marginRight="3dp"

            android:src="@drawable/fairnessteaser" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/imageTop"
            android:layout_below="@+id/app_bar"
            android:background="@drawable/red_button"
            style="@style/button_text"
            android:layout_alignBaseline="@+id/imageTop"
            android:text="Explore" />

        <TextView
            android:id="@+id/whatsNew"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageTop"
            android:text="What's new" />

        <com.snappy.stevekamau.cosmeticsapp.InnerGridView
            android:id="@+id/grid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/whatsNew"
            android:columnWidth="100dp"
            android:gravity="center"
            android:horizontalSpacing="3dp"
            android:listSelector="@drawable/list_row_selector"
            android:numColumns="3"
            android:padding="3dp"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />


    </RelativeLayout>
</ScrollView>
<fragment
    android:id="@+id/fragment_navigation_drawer"
    android:name="com.snappy.stevekamau.cosmeticsapp.NavigationDrawerFragment"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"
    tools:layout="@layout/fragment_navigation_drawer"></fragment>


您是否打开并看到开发工具show border,它将显示边框、边距、填充等。@Turtle,恐怕我还没有这样做,然后我添加自定义网格视图以替换网格视图?