1.ViewPagerIndicator的使用
(1)如何在运行开源框架的例子中找到自己需要的代码
a.根据命名找相关的类
b.运行项目,根据界面的字段进行全局搜索
*Search---->File---->File Search
(2)布局
<span style="font-size:14px;"><span style="font-size:14px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<android.support.v4.view.ViewPager
android:id="@+id/vp_menu_detail"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout></span></span>
(3)使用
<span style="font-size:14px;"><span style="font-size:14px;">public class SampleTabsDefault extends FragmentActivity {
private static final String[] CONTENT = new String[] { "Recent", "Artists", "Albums", "Songs", "Playlists", "Genres" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs);
FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
class GoogleMusicAdapter extends FragmentPagerAdapter {
public GoogleMusicAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
}
@Override
public CharSequence getPageTitle(int position) {//一般在普通的ViewPager适配器中添加该方法
return CONTENT[position % CONTENT.length].toUpperCase();
}
@Override
public int getCount() {
return CONTENT.length;
}
}
}</span></span>
2.ViewPagerIndicator样式修改&切换下个页面
1.使用开源框架的代码是效果不一样可能activity的样式不同,改变样式,如果背景为黑色,可以手动改变activity的背景
(1)
<span style="font-size:14px;"><span style="font-size:14px;"> android:theme="@style/Theme.PageIndicatorDefaults"</span></span>
(2)改变背景颜色
<span style="font-size:14px;"><span style="font-size:14px;">android:background="#fff"</span></span>
(3)点击样式,改变样式
2.监听当前ViewPager的页面并加一
<span style="font-size:14px;">// 跳转下一个页面
@OnClick(R.id.btn_next)
public void nextPage(View view) {
int currentItem = mViewPager.getCurrentItem();
mViewPager.setCurrentItem(++currentItem);
}</span>
3.滑动事件的处理
(1)请求父控件和祖宗控件不要拦截触摸事件
<span style="font-size:14px;">public boolean dispatchTouchEvent(MotionEvent ev){
getParent().requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
}
</span>
(2)自定义一个ViewPager,请求父控件和祖宗控件不要拦截触摸事件,但第一个页面是要拦截(特殊)
<span style="font-size:14px;">public class HorizontalViewPager extends ViewPager {
public HorizontalViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HorizontalViewPager(Context context) {
super(context);
}
/**
* 事件分发, 请求父控件及祖宗控件是否拦截事件
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (getCurrentItem() != 0) {
getParent().requestDisallowInterceptTouchEvent(true);// 用getParent去请求,
// 不拦截
} else {// 如果是第一个页面,需要显示侧边栏, 请求父控件拦截
getParent().requestDisallowInterceptTouchEvent(false);// 拦截
}
return super.dispatchTouchEvent(ev);
}
}</span>
4.头条新闻展示&BitmapUtils
(1)联网获取内容
<span style="font-size:14px;"> //联网获取数据
private void getDataFromServer() {
HttpUtils utils = new HttpUtils();
utils.send(HttpMethod.GET, mUrl, new RequestCallBack<String>() {
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
String result = (String) responseInfo.result;
System.out.println("页签详情页返回结果:" + result);
parseData(result); //解析Json
}
@Override
public void onFailure(HttpException error, String msg) {
Toast.makeText(mActivity, msg, Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
});
}</span>
a.Json内容
<span style="font-size:14px;">{
"data": {
"countcommenturl": "http://zhbj.qianlong.com/client/content/countComment/",
"more": "/10007/list_2.json",
"news": [
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35311,
"listimage": "http://10.0.2.2:8080/zhbj/10007/2078369924F9UO.jpg",
"pubdate": "2014-10-1113:18",
"title": "网上大讲堂第368期预告:义务环保人人有责",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35312,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1509585620ASS3.jpg",
"pubdate": "2014-10-1111:20",
"title": "马路改建为停车场车位年费高达3000元",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35313,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1506815057D99I.jpg",
"pubdate": "2014-10-1110:34",
"title": "北京两年内将迁出1200家工业污染企业",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35314,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1505891536Z82T.jpg",
"pubdate": "2014-10-1110:08",
"title": "大雾再锁京城机场航班全部延误",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35315,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1483727032VMXT.jpg",
"pubdate": "2014-10-1110:03",
"title": "APEC会议期间调休企业员工盼同步放假",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35316,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1481879990BEMG.jpg",
"pubdate": "2014-10-1109:59",
"title": "机械“龙马”巡演17日亮相奥园",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35310,
"listimage": "http://10.0.2.2:8080/zhbj/10007/14800329488K7F.jpg",
"pubdate": "2014-10-1109:54",
"title": "门头沟获批100套限价房",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35319",
"id": 35318,
"listimage": "http://10.0.2.2:8080/zhbj/10007/14791094274LT9.jpg",
"pubdate": "2014-10-1109:52",
"title": "APEC期间净空区放带灯风筝可拘留",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35314",
"id": 35314,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1478185906G9WQ.jpg",
"pubdate": "2014-10-1109:48",
"title": "今起两自住房摇号",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35117",
"id": 35117,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1477262385PASS.jpg",
"pubdate": "2014-10-1109:45",
"title": "故宫神武门广场拟夜间开放停车",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
}
],
"title": "北京",
"topic": [
{
"description": "11111111",
"id": 10101,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1452327318UU91.jpg",
"sort": 1,
"title": "北京",
"url": "http://10.0.2.2:8080/zhbj/10007/list_1.json"
},
{
"description": "22222222",
"id": 10100,
"listimage": "http://10.0.2.2:8080/zhbj/10007/1452327318UU91.jpg",
"sort": 2,
"title": "222222222222",
"url": "http://10.0.2.2:8080/zhbj/10007/list_1.json"
}
],
"topnews": [
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35301",
"id": 35301,
"pubdate": "2014-04-0814:24",
"title": "蜗居生活",
"topimage": "http://10.0.2.2:8080/zhbj/10007/1452327318UU91.jpg",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35125",
"id": 35125,
"pubdate": "2014-04-0809:09",
"title": "中秋赏月",
"topimage": "http://10.0.2.2:8080/zhbj/10007/1452327318UU92.jpg",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35125",
"id": 35126,
"pubdate": "2014-04-0809:09",
"title": "天空翱翔",
"topimage": "http://10.0.2.2:8080/zhbj/10007/1452327318UU93.jpg",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
},
{
"comment": true,
"commentlist": "http://10.0.2.2:8080/zhbj/10007/comment_1.json",
"commenturl": "http://zhbj.qianlong.com/client/user/newComment/35125",
"id": 35127,
"pubdate": "2014-04-0809:09",
"title": "感官设计",
"topimage": "http://10.0.2.2:8080/zhbj/10007/1452327318UU94.png",
"type": "news",
"url": "http://10.0.2.2:8080/zhbj/10007/724D6A55496A11726628.html"
}
]
},
"retcode": 200
}</span>
b.bean类
<span style="font-size:14px;">/**
* 页签详情页数据
*
* @author Kevin
*
*/
public class TabData {
public int retcode;
public TabDetail data;
public class TabDetail {
public String title;
public String more;
public ArrayList<TabNewsData> news;
public ArrayList<TopNewsData> topnews;
@Override
public String toString() {
return "TabDetail [title=" + title + ", news=" + news
+ ", topnews=" + topnews + "]";
}
}
/**
* 新闻列表对象
*
* @author Kevin
*
*/
public class TabNewsData {
public String id;
public String listimage;
public String pubdate;
public String title;
public String type;
public String url;
@Override
public String toString() {
return "TabNewsData [title=" + title + "]";
}
}
/**
* 头条新闻
*
* @author Kevin
*
*/
public class TopNewsData {
public String id;
public String topimage;
public String pubdate;
public String title;
public String type;
public String url;
@Override
public String toString() {
return "TopNewsData [title=" + title + "]";
}
}
@Override
public String toString() {
return "TabData [data=" + data + "]";
}
}</span>
c.Gson解析
<span style="font-size:14px;">Gson gson = new Gson();
mTabDetailData = gson.fromJson(result, TabData.class);</span>
(4)头条新闻的展示(ViewPager展示图片)
1.父控件会拦截ViewPager的滑动事件,所以自定义一个ViewPager叫父控件不要拦截
加上dispatchTouchEvent
2.图片不能撑开界面,留有空白
<span style="font-size:14px;">ImageView image = new ImageView(mActivity);
image.setScaleType(ScaleType.FIT_XY);// 基于控件大小填充图片</span>
<span style="font-size:14px;">private BitmapUtils utils;
utils = new BitmapUtils(mActivity);
utils.configDefaultLoadingImage(R.drawable.topnews_item_default);// 设置默认图片
ImageView image = new ImageView(mActivity);
image.setScaleType(ScaleType.FIT_XY);// 基于控件大小填充图片
TopNewsData topNewsData = mTopNewsList.get(position);
utils.display(image, topNewsData.topimage);// 传递imagView对象和图片地址
container.addView(image);</span>
5.智慧北京事件处理及总结
1.图片的ViewPager与父控件事件冲突,发生矛盾
使用另外的方法解决,不是北京时禁掉slidingMenu
注意:ViewPager与TabPageIndicator进行绑定后,监听事件需要设置给Indicator而不是ViewPager
mIndicator = (TabPageIndicator) view.findViewById(R.id.indicator);
// mViewPager.setOnPageChangeListener(this);//注意:当viewpager和Indicator绑定时,
// 滑动监听需要设置给Indicator而不是viewpager
mIndicator.setOnPageChangeListener(this);
@Override
public void onPageSelected(int arg0) {
System.out.println("onPageSelected:" + arg0);
MainActivity mainUi = (MainActivity) mActivity;
SlidingMenu slidingMenu = mainUi.getSlidingMenu();
if (arg0 == 0) {//只有在第一个页面(北京), 侧边栏才允许出来
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
} else {
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
}
----自定义一个ViewPager(展示图片的)------------------------,重写监听
根据位移判断是x方向移动还是y方向移动
/**
* 事件分发, 请求父控件及祖宗控件是否拦截事件 1. 右划, 而且是第一个页面, 需要父控件拦截 2. 左划, 而且是最后一个页面, 需要父控件拦截
* 3. 上下滑动, 需要父控件拦截
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
getParent().requestDisallowInterceptTouchEvent(true);// 不要拦截,
// 这样是为了保证ACTION_MOVE调用
startX = (int) ev.getRawX();
startY = (int) ev.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int endX = (int) ev.getRawX();
int endY = (int) ev.getRawY();
if (Math.abs(endX - startX) > Math.abs(endY - startY)) {// 左右滑动
if (endX > startX) {// 右划
if (getCurrentItem() == 0) {// 第一个页面, 需要父控件拦截
getParent().requestDisallowInterceptTouchEvent(false);
}
} else {// 左划
if (getCurrentItem() == getAdapter().getCount() - 1) {// 最后一个页面,
// 需要拦截
getParent().requestDisallowInterceptTouchEvent(false);
}
}
} else {// 上下滑动
getParent().requestDisallowInterceptTouchEvent(false);
}
break;
default:
break;
}
return super.dispatchTouchEvent(ev);
}
6.头条新闻标题设置
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#a000"
android:padding="3dp" >
7.使用ViewpagerIndicator实现头条新闻位置指示器
(1)小点
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#a000"
android:padding="3dp" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="16sp" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dip"
app:fillColor="#f00"
app:pageColor="@android:color/darker_gray"
app:radius="3dp"
app:strokeWidth="0dp" />
</RelativeLayout>
(2)使用-----因为ViewPager与indicator关联,所以给indicator设置
private CirclePageIndicator mIndicator;// 头条新闻位置指示器
mViewPager.setAdapter(new TopNewsAdapter());
mIndicator.setViewPager(mViewPager);
mIndicator.setSnap(true);// 支持快照显示
mIndicator.setOnPageChangeListener(this);
mIndicator.onPageSelected(0);// 让指示器重新定位到第一个点
(3)改变样式----例子程序中提供了三种方法
app:fillColor="#f00"
app:pageColor="@android:color/darker_gray"
app:radius="3dp"
app:strokeWidth="0dp"
需要把命名空间拷贝过来
xmlns:app="http://schemas.android.com/apk/res-auto"
8.新闻列表展示&item布局编写
(1)ListView的item布局
ImageView: 使图片撑大成imageview的大小
Imageview写死大小
android:scaleType="fitXY"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<ImageView
android:id="@+id/iv_pic"
android:layout_width="110dp"
android:layout_height="70dp"
android:scaleType="fitXY"
android:padding="1dp"
android:background="@android:color/darker_gray"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/image_demo" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/iv_pic"
android:text="新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题"
android:textColor="#000"
android:maxLines="2"
android:ellipsize="end"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/tv_title"
android:text="2015-03-16 16:20"
android:layout_alignBottom="@id/iv_pic"
android:textColor="@android:color/darker_gray"
android:textSize="16sp" />
</RelativeLayout>
9.新闻列表展示&HeaderView
(1) android:cacheColorHint="#fff" 缓存时listview的颜色
(2)新闻列表适配器
/**
* 新闻列表的适配器
*
* @author Kevin
*
*/
class NewsAdapter extends BaseAdapter {
private BitmapUtils utils;
public NewsAdapter() {
utils = new BitmapUtils(mActivity);
utils.configDefaultLoadingImage(R.drawable.pic_item_list_default);
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public TabNewsData getItem(int position) {
return mNewsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = View.inflate(mActivity, R.layout.list_news_item,
null);
holder = new ViewHolder();
holder.ivPic = (ImageView) convertView
.findViewById(R.id.iv_pic);
holder.tvTitle = (TextView) convertView
.findViewById(R.id.tv_title);
holder.tvDate = (TextView) convertView
.findViewById(R.id.tv_date);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
TabNewsData item = getItem(position);
holder.tvTitle.setText(item.title);
holder.tvDate.setText(item.pubdate);
utils.display(holder.ivPic, item.listimage);
return convertView;
}
}
static class ViewHolder {
public TextView tvTitle;
public TextView tvDate;
public ImageView ivPic;
}
(3)要想整体能滑动,可以把ViewPager变成listview的头布局
头布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.itheima.zhbj52.view.TopNewsViewPager
android:id="@+id/vp_news"
android:layout_width="match_parent"
android:layout_height="200dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#a000"
android:padding="3dp" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="16sp" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dip"
app:fillColor="#f00"
app:pageColor="@android:color/darker_gray"
app:radius="3dp"
app:strokeWidth="0dp" />
</RelativeLayout>
</RelativeLayout>
加到listview上
View view = View.inflate(mActivity, R.layout.tab_detail_pager, null);
// 加载头布局
View headerView = View.inflate(mActivity, R.layout.list_header_topnews,
null);
ViewUtils.inject(this, view);
ViewUtils.inject(this, headerView);
// 将头条新闻以头布局的形式加给listview
lvList.addHeaderView(headerView);
10.自定义下拉刷新
下拉刷新头部用LinearLayout,其他的可能会出问题
(1)自定义一个listview,替换原来的listview
/**
* 下拉刷新的ListView
*
* @author Kevin
*
*/
public class RefreshListView extends ListView {
private View mHeaderView;
public RefreshListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initHeaderView();
}
public RefreshListView(Context context, AttributeSet attrs) {
super(context, attrs);
initHeaderView();
}
public RefreshListView(Context context) {
super(context);
initHeaderView();
}
/**
* 初始化头布局
*/
private void initHeaderView() {
mHeaderView = View.inflate(getContext(), R.layout.refresh_header, null);
this.addHeaderView(mHeaderView);
mHeaderView.measure(0, 0);
int mHeaderViewHeight = mHeaderView.getMeasuredHeight();
mHeaderView.setPadding(0, -mHeaderViewHeight, 0, 0);//隐藏头布局
}
}
(2)定义头布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<ImageView
android:id="@+id/iv_arr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/common_listview_headview_red_arrow" />
<ProgressBar
android:id="@+id/pb_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible" />
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下拉刷新"
android:textColor="#f00"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2015-03-10 17:07:07"
android:textColor="@android:color/darker_gray"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
(3)一个ListView可以加多个HeadView,最先添加的在最上面