简体   繁体   English

在Android中向gridview添加页眉和页脚

[英]Adding a header and a footer to a gridview in Android

I am trying to create users' profile pages in my Android app with the following features: - header - gridview showing a bunch of photos from that user - footer (a downloading icon when the app is downloading more photos in the gridview) - the header needs to move together with the gridview 我试图在具有以下功能的Android应用程序中创建用户的个人资料页面:-标头-显示该用户的照片的gridview-页脚(当应用程序在gridview中下载更多照片时为下载图标)-标头需要与gridview一起移动

In other words, the user experience on the profile page would be very similar to the user experience in an Instagram user profile page. 换句话说,个人资料页面上的用户体验将非常类似于Instagram用户个人资料页面上的用户体验。

The issue is that gridview does not support headers and footers. 问题是gridview不支持页眉和页脚。

Any solutions, or libraries I could use to deliver the desired user experience? 我可以使用任何解决方案或库来提供所需的用户体验吗?

Just use multiple RelativeLayouts. 只需使用多个RelativeLayouts。

Create your header layout (50dp or whatever) aligned to parent top. 创建与父顶部对齐的页眉布局(50dp或其他格式)。 Then create a second layout aligned to the bottom of the page (this will be your footer). 然后创建与页面底部对齐的第二个布局(这将是您的页脚)。 Then have another layout set to "below" the header and "above" the footer which will contain your GridView. 然后将另一个布局设置为包含标题的“下方”页眉和“上方”页脚,其中将包含GridView。

It should look like: 它应该看起来像:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true" >

        /* ANYTHING YOU WANT IN YOUR HEADER */

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/gridview"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/header"
        android:layout_above="@+id/footer" >

        /* GRIDVIEW HERE */

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true" >

        /* ANYTHING YOU WANT IN YOUR FOOTER */

    </RelativeLayout>

</RelativeLayout>

Hopefully this helps. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM