Android gridview和自定义标题

Android gridview和自定义标题,android,gridview,Android,Gridview,我正在努力实现以下GUI: 对于红线下的9个元素(线下的所有内容都应该是可滚动的),我使用了一个gridview布局,它按预期工作。但事实上我不知道我是怎么头球的 到目前为止,我的xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="m

我正在努力实现以下GUI:

对于红线下的9个元素(线下的所有内容都应该是可滚动的),我使用了一个gridview布局,它按预期工作。但事实上我不知道我是怎么头球的

到目前为止,我的xml:

<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:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:background = "@drawable/t"
   tools:context=".AppStarter" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">
    <GridView 
        android:id="@+id/gridview"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:numColumns="3"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp" />
 </LinearLayout>
</RelativeLayout>

我的想法是在gridview上添加一个额外的linearLayout,但是这种方法没有提供预期的结果。有没有办法实现这个标题


提前谢谢

您可以为标题使用水平线性布局,并使用父相对视图将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:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:background = "@drawable/t"
   tools:context=".AppStarter" >

   <!-- Header section -->
   <LinearLayout
       android:id="@+id/headerlayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"
       android:orientation="horizontal" >

           <!-- Example header content -->
           <FrameLayout 
               android:id="@+id/frame1"
               android:layout_width="wrap_content" 
               android:layout_height="match_parent" />

           <FrameLayout 
               android:id="@+id/frame2"
               android:layout_width="wrap_content" 
               android:layout_height="match_parent" />

   </LinearLayout>

   <!-- GridView section -->
   <GridView 
       android:id="@+id/gridview"
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"
       android:layout_below="@id/headerlayout" <!-- This line sets relative position of GridView -->
       android:numColumns="3"
       android:verticalSpacing="10dp"
       android:horizontalSpacing="10dp"
       android:stretchMode="columnWidth"
       android:gravity="center"
       android:layout_marginLeft="2sp"
       android:layout_marginRight="5sp"
       android:layout_marginTop="0sp" />
</RelativeLayout>

android:numColumns=“3”
android:verticalSpacing=“10dp”
android:horizontalSpacing=“10dp”
android:stretchMode=“columnWidth”
android:gravity=“center”
android:layout_marginLeft=“2sp”
android:layout_marginRight=“5sp”
android:layout_marginTop=“0sp”/

您可以尝试我自己的实现。经过多次尝试,我决定写自己的代码


这不是标题,因为当您滚动gridView时,标题应该向上滚动