android footer view

引用:http://www.eoeandroid.com/code/2011/1208/303.html

导读:其实我们主要实现的就是在页面的地步有一个分类,有了这个我们的用户就会感觉到很友好。

 

       下面详细说说这个页面是怎么做出来的:

       1、这个页面最下方可以看到一个TAB页签,分别是“主页”、“提及”等等,这个是一个在底部的TAB分页样式。

       2、这个页面就是“主页”这个子页面,是嵌入到上面说的TAB布局中的。由3个部分组成,分别是最上面的状态栏(包含2个按钮,和一个文本区)、中间的列表、最下方的“更多”按钮(当更多按钮点击时,会加载更多数据,并且出现LOADING提示)

 

01<?xml version="1.0" encoding="utf-8"?>
02<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
03android:layout_width="fill_parent"
04android:layout_height="fill_parent">
05<LinearLayout
06android:background="#ffffffff"
07android:layout_width="fill_parent"
08android:layout_height="fill_parent"
09android:orientation="vertical" />
10<include
11android:id="@+id/head_line"
12layout="@layout/head_line"
13android:layout_width="fill_parent"
14android:layout_height="wrap_content" />
15<ListView
16android:cacheColorHint="#00000000"
17android:id="@id/android:list"
18android:layout_width="fill_parent"
19android:fastScrollEnabled="false"
20android:layout_height="wrap_content"
21android:paddingTop="45.0dip"
22android:fadingEdge="none"
23android:paddingBottom="50.0dip"
24android:divider="@drawable/list_divider"
25android:clipToPadding="false" />
26 
27</FrameLayout>
上面这段代码,就生成了列表,和顶部的状态栏。顶部的状态栏是通过<include>标签引入的
01<RelativeLayout
02android:background="@drawable/header"
03android:layout_width="fill_parent"
04android:layout_height="wrap_content"
05xmlns:android="http://schemas.android.com/apk/res/android">
06 
07 
08<Button
09android:id="@+id/top_btn_left"
10android:textColor="@color/button_text_selector"
11android:background="@drawable/top_refresh_selector"
12android:layout_width="wrap_content"
13android:layout_height="wrap_content"
14android:layout_marginLeft="12.0dip"
15android:layout_alignParentLeft="true"
16android:layout_centerVertical="true" />
17 
18 
19<Button
20android:id="@+id/top_btn_right"
21android:textColor="@color/button_text_selector"
22android:background="@drawable/top_edit_selector"
23android:layout_width="wrap_content"
24android:layout_height="wrap_content"
25android:layout_marginRight="12.0dip"
26android:layout_alignParentRight="true"
27android:layout_centerVertical="true" />
28 
29 
30<TextView
31android:id="@+id/top_title" android:textSize="22.0sp"
32android:textColor="@color/head_line_text"
33android:ellipsize="middle"
34android:gravity="center_horizontal"
35android:layout_width="wrap_content"
36android:layout_height="wrap_content"
37android:text="@string/user_name"
38android:singleLine="true"
39android:layout_toLeftOf="@id/top_btn_right"
40android:layout_toRightOf="@id/top_btn_left"
41android:layout_centerInParent="true"
42android:layout_alignWithParentIfMissing="true" />
43 
44</RelativeLayout>
是一个最简单的横向排列布局,就不用多介绍了 3、然后是这个FooterView是怎么添加进来的,看代码
01@Override
02protected void onCreate(Bundle savedInstanceState) {
03super.onCreate(savedInstanceState);
04setContentView(R.layout.home);
05setUpViews();// 设置视图
06setUpListeners();// 设置侦听器
07fillInitData();// 填充初始化数据
08}
09 
10 
11/**
12* 设置视图
13*/
14private void setUpViews() {
15listView = getListView();// 得到ListView
16listFooter = (LinearLayout) LayoutInflater.from(this).inflate(
17R.layout.list_footer, null);
18listView.addFooterView(listFooter);// 添加FooterView
19more = (TextView) findViewById(R.id.more);
20loading = (LinearLayout) findViewById(R.id.loading);
21}
通过ListView.addFooterView()方法,来给列表添加一个FooterView,而这个FooterView,也是来自一个layout.xml
01<?xml version="1.0" encoding="UTF-8"?>
02<LinearLayout android:layout_width="fill_parent"
03android:layout_height="wrap_content" android:minHeight="?android:listPreferredItemHeight"
04xmlns:android="http://schemas.android.com/apk/res/android">
05<TextView android:textSize="16.0sp" android:textColor="#ff545454"
06android:gravity="center" android:id="@+id/more"android:layout_width="fill_parent"
07android:layout_height="fill_parent" android:text="@string/more" />
08<LinearLayout android:gravity="center"
09android:layout_gravity="center" android:orientation="horizontal"
10android:id="@+id/loading" android:layout_width="fill_parent"
11android:layout_height="fill_parent">
12<ProgressBar android:layout_gravity="center_vertical"
13android:id="@+id/footprogress" android:layout_width="wrap_content"
14android:layout_height="wrap_content"android:indeterminateBehavior="repeat"
15style="?android:progressBarStyleSmallInverse" />
16<TextView android:textColor="#ff000000" android:gravity="left|center"
17android:padding="3.0px" android:layout_width="wrap_content"
18android:layout_height="wrap_content" android:text="@string/loading" />
19</LinearLayout>
20 
21</LinearLayout>
这个FooterView包含一个“更多”的文本框,和一个“读取中”文本框。这里我没弄明白的是,为什么一开始默认只会显示“更多”,读取栏不会显示出来,需要
1more.setOnClickListener(new OnClickListener() {
2@Override
3public void onClick(View v) {
4more.setVisibility(View.GONE);
5loading.setVisibility(View.VISIBLE);
6}
7});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值