与列表视图页眉和页脚 [英] listview with header and footer

查看:135
本文介绍了与列表视图页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个Android设备上查看,用一个ListView作为页眉和页脚。
到目前为止,只有管理只出现在头部。
这里是一个图片,说明我想要什么,我已经得到了。

有谁知道我做错了吗?
干目前的code:

 <?XML版本=1.0编码=UTF-8&GT?; < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:背景=#FFFFFF><! - 头开始 - >
<的LinearLayout机器人:ID =@ + ID /头
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:背景=@布局/ header_gradient
        机器人:layout_margin =5dip
        机器人:paddingTop =13dip
        机器人:paddingBottom会=8DIP>
    <! - 标识开始 - >
    < ImageView的机器人:SRC =@绘制/标志的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:layout_marginLeft =10dip/>
    <! - 标志完 - >
< / LinearLayout中>
<! - 标题结束 - ><! - 内容 - >
    < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
              机器人:layout_height =FILL_PARENT
              机器人:layout_width =FILL_PARENT
              机器人:方向=垂直
              机器人:比重=中心>        <的LinearLayout机器人:方向=横向
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_margin =5dip>            < EditText上机器人:ID =@ + ID / SEARCHTEXT
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =FILL_PARENT
                    机器人:layout_weight =1/>            < ImageButton的机器人:ID =@ + ID /搜索按钮
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_width =WRAP_CONTENT
                    机器人:SRC =@机器人:可绘制/ ic_menu_search/>
        < / LinearLayout中>        < ListView的机器人:ID =@ + ID / lstNews
                机器人:layout_height =FILL_PARENT
                机器人:layout_width =FILL_PARENT
                机器人:layout_marginLeft =5dip
                机器人:layout_marginRight =5dip/>
    < / LinearLayout中>&所述;! - 页脚开始 - >
<的LinearLayout机器人:ID =@ + ID /页脚
     机器人:layout_width =FILL_PARENT
     机器人:layout_height =30dip
     机器人:背景=@布局/ footer_gradient
     机器人:layout_margin =5dip
     机器人:paddingTop =5dip
     机器人:paddingLeft =5dip
     机器人:layout_alignParentBottom =真正的>
    <的TextView的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=#FFFFFF机器人:文本=高级研究所德/>
    <的TextView的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=#FFFFFF机器人:文字样式=大胆的android:文本=ENGENHARIA/>
    <的TextView的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=#FFFFFF机器人:文本=波尔图/>
< / LinearLayout中>
<! - 页脚完 - >< / LinearLayout中>


解决方案

一种选择是使用RelativeLayout的来代替。

首先,你需要改变你的最外层的的LinearLayout RelativeLayout的

接下来的一步是添加属性的android:layout_above =@ ID /内容来的标题

 <! - 头开始 - >
<的LinearLayout机器人:ID =@ + ID /头
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@布局/ header_gradient
    机器人:layout_margin =5dip
    机器人:paddingTop =13dip
    机器人:paddingBottom会=8DIP
    机器人:layout_above =@ ID /内容>

最后一步是添加属性的android:layout_above =@ ID /页脚机器人:ID =@ + ID /内容来包含的内容和的LinearLayout ListView控件即

 <! - 内容 - >
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
          机器人:ID =@ + ID /内容
          机器人:layout_height =FILL_PARENT
          机器人:layout_width =FILL_PARENT
          机器人:方向=垂直
          机器人:比重=中心
          机器人:layout_above =@ ID /页脚>

I am trying to build an Android View, with a listview as a header and footer. so far only managed that only appears to the header. Here is a picture that explains what I want and that I've got.

Does anyone know what I'm doing wrong? Dry the current code:

<?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="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff">

<!--  Header Starts-->
<LinearLayout android:id="@+id/header" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="@layout/header_gradient" 
        android:layout_margin="5dip" 
        android:paddingTop="13dip" 
        android:paddingBottom="8dip">
    <!-- Logo Start-->
    <ImageView android:src="@drawable/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" />
    <!-- Logo Ends -->
</LinearLayout>
<!--  Header Ends -->

<!-- Content -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:layout_height="fill_parent"
              android:layout_width="fill_parent"
              android:orientation="vertical"
              android:gravity="center">

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

            <EditText android:id="@+id/searchText"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"/>

            <ImageButton android:id="@+id/searchButton"
                    android:layout_height="wrap_content" 
                    android:layout_width="wrap_content" 
                    android:src="@android:drawable/ic_menu_search" />
        </LinearLayout> 

        <ListView android:id="@+id/lstNews" 
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                android:layout_marginLeft="5dip"
                android:layout_marginRight="5dip" />
    </LinearLayout>

<!-- Footer Start -->
<LinearLayout android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="30dip" 
     android:background="@layout/footer_gradient" 
     android:layout_margin="5dip" 
     android:paddingTop="5dip" 
     android:paddingLeft="5dip" 
     android:layout_alignParentBottom="true">
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:text="Instituto Superior de " />
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textStyle="bold" android:text="Engenharia" />
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:text=" do Porto" />
</LinearLayout>
<!-- Footer Ends --></LinearLayout>

解决方案

One option is to use a RelativeLayout instead.

Firstly you will need to change your outermost LinearLayout to a RelativeLayout.

The next step is to add the property android:layout_above="@id/content" to the header.

<!--  Header Starts-->
<LinearLayout android:id="@+id/header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/header_gradient" 
    android:layout_margin="5dip" 
    android:paddingTop="13dip" 
    android:paddingBottom="8dip"
    android:layout_above="@id/content">

The final step is to add the properties android:layout_above="@id/footer" and android:id="@+id/content" to the LinearLayout that contains the content and the listview i.e.

<!-- Content -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
          android:id="@+id/content"
          android:layout_height="fill_parent"
          android:layout_width="fill_parent"
          android:orientation="vertical"
          android:gravity="center"
          android:layout_above="@id/footer">

这篇关于与列表视图页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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