如何将页脚添加到Android的gridview的布局 [英] How to add a footer to gridview layout in android

查看:148
本文介绍了如何将页脚添加到Android的gridview的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要某种类型的页脚视图添加到Android的一个GridView的布局,没有,我可以找到这个官方文档,我一直没能找到实际工作中我的谷歌搜索的方法,已任何人都取得了这样的事?我需要一个按钮,将显示在GridView的底部,这样我可以添加更多的照片的onclick,有点像从Instagram的下面的例子中,任何帮助会走很长的路的感谢!

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直><的LinearLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向
    机器人:layout_margin =5DP>    < ImageView的
        机器人:ID =@ + ID / profile_user_avatar
        机器人:layout_width =48像素
        机器人:layout_height =48像素
        机器人:adjustViewBounds =真
        机器人:layout_marginTop =5DP/>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直
        机器人:paddingLeft =5DP>        <的TextView
            机器人:ID =@ + ID / profile_realname
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:重力=左
            机器人:TEXTSIZE =20dp
            机器人:文字样式=大胆
             />        <的TextView
            机器人:ID =@ + ID / profile_username
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginBottom =2DP
            机器人:重力=左/>
    < / LinearLayout中>
< / LinearLayout中><的LinearLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_margin =5DP
        机器人:layout_weight =1
        机器人:方向=垂直>        <的TextView
            机器人:ID =@ + ID / tweets_stat
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ button_color_light
            机器人:比重=中心
            机器人:填充=10dp
            机器人:TEXTSIZE =20dp
            机器人:文字样式=大胆
            机器人:文字颜色=#FFFFFF/>        <的TextView
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ button_color_dark
            机器人:比重=中心
            机器人:填充=10dp
            机器人:文字=鸣叫
            机器人:TEXTSIZE =15dp
            机器人:文字样式=大胆
            机器人:文字颜色=#FFFFFF/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_margin =5DP
        机器人:layout_weight =1
        机器人:方向=垂直>        <的TextView
            机器人:ID =@ + ID / followers_stat
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ button_color_light
            机器人:比重=中心
            机器人:填充=10dp
            机器人:TEXTSIZE =20dp
            机器人:文字样式=大胆
            机器人:文字颜色=#FFFFFF/>        <的TextView
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ button_color_dark
            机器人:比重=中心
            机器人:填充=10dp
            机器人:文字=关注
            机器人:TEXTSIZE =15dp
            机器人:文字样式=大胆
            机器人:文字颜色=#FFFFFF/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_margin =5DP
        机器人:layout_weight =1
        机器人:方向=垂直>        <的TextView
            机器人:ID =@ + ID / following_stat
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ button_color_light
            机器人:比重=中心
            机器人:填充=10dp
            机器人:TEXTSIZE =20dp
            机器人:文字样式=大胆
            机器人:文字颜色=#FFFFFF/>        <的TextView
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ button_color_dark
            机器人:比重=中心
            机器人:填充=10dp
            机器人:文字=继
            机器人:TEXTSIZE =15dp
            机器人:文字样式=大胆
            机器人:文字颜色=#FFFFFF/>
    < / LinearLayout中>
< / LinearLayout中>< GridView控件
    机器人:ID =@ + ID / gridView1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:columnWidth时=90dp
    机器人:比重=中心
    机器人:horizo​​ntalSpacing =10dp
    机器人:为numColumns =auto_fit
    机器人:stretchMode =columnWidth时
    机器人:verticalSpacing =10dp>
< / GridView的><按钮
    机器人:ID =@ + ID / profile_button
    风格=@风格/ TextAppearance.Button
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_marginBottom =30dp
    机器人:layout_marginTop =30dp
    机器人:背景=@绘制/ button_background
    机器人:文字=装载更多的照片/>
< / LinearLayout中>


解决方案

您可以使用有效的线沿线的东西添加页脚网格项:
https://github.com/commonsguy/cwac-endless

这会不会像您所需要的,它看起来更像是最后的网格项是一个按钮。

另一种选择是有一个相对布局其中对齐按钮在屏幕的底部,最初它的可见性设置为走和仅当用户点击网页的端部被设置为可见。这更是一个黑客/变通办法的。

I need to add a footer view of some kind to a gridview layout in android, there is no official documentation that I can find for this and I have not been able to find a method that actually works in my google searches, has anyone achieved anything like this? I need to make a button that will show up the bottom of the gridview so that I can add more photos onclick, sort of like the below example from instagram, any help would go a long way thanks!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_margin="5dp" >

    <ImageView
        android:id="@+id/profile_user_avatar"
        android:layout_width="48px"
        android:layout_height="48px"
        android:adjustViewBounds="true"
        android:layout_marginTop="5dp" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:paddingLeft="5dp">

        <TextView
            android:id="@+id/profile_realname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:textSize="20dp"
            android:textStyle="bold"
             />

        <TextView
            android:id="@+id/profile_username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp"
            android:gravity="left" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tweets_stat"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/button_color_light"
            android:gravity="center"
            android:padding="10dp"
            android:textSize="20dp"
            android:textStyle="bold"
            android:textColor="#FFFFFF" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/button_color_dark"
            android:gravity="center"
            android:padding="10dp"
            android:text="Tweets"
            android:textSize="15dp"
            android:textStyle="bold"
            android:textColor="#FFFFFF" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/followers_stat"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/button_color_light"
            android:gravity="center"
            android:padding="10dp"
            android:textSize="20dp"
            android:textStyle="bold"
            android:textColor="#FFFFFF" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/button_color_dark"
            android:gravity="center"
            android:padding="10dp"
            android:text="Followers"
            android:textSize="15dp"
            android:textStyle="bold"
            android:textColor="#FFFFFF" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/following_stat"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/button_color_light"
            android:gravity="center"
            android:padding="10dp"
            android:textSize="20dp"
            android:textStyle="bold"
            android:textColor="#FFFFFF" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/button_color_dark"
            android:gravity="center"
            android:padding="10dp"
            android:text="Following"
            android:textSize="15dp"
            android:textStyle="bold"
            android:textColor="#FFFFFF" />
    </LinearLayout>
</LinearLayout>

<GridView
    android:id="@+id/gridView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:columnWidth="90dp"
    android:gravity="center"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:verticalSpacing="10dp" >
</GridView>

<Button
    android:id="@+id/profile_button"
    style="@style/TextAppearance.Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="30dp"
    android:layout_marginTop="30dp"
    android:background="@drawable/button_background"
    android:text="Load more photos" />
</LinearLayout>

解决方案

You could effectively add a footer grid item using something along the lines of: https://github.com/commonsguy/cwac-endless

This wouldn't look like what you require, it would look more like the last grid item is a button.

The other option is to have a relative layout which aligns the button to the bottom of the screen, initially its visibility is set to gone and is set to visible only when the user hits the end of the page. This is more of a hack/workaround.

这篇关于如何将页脚添加到Android的gridview的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆