首页 > 其他 > 详细

AbsListView的Header不能直接固定大小为0

时间:2015-02-20 02:03:28      阅读:305      评论:0      收藏:0      [点我收藏+]

?

直接上代码:

LinearLayout mLayout = new LinearLayout(this);
LayoutInflater.from(this).inflate(R.layout.header, mLayout, true);
mListView.addHeaderView(mLayout);?

?

如果设置(在Layout画出来之后):

LayoutParams lp = mLayout.getLayoutParams();
lp.height = 0;
mLayout.setLayoutParams(lp);

?

则mLayout的高度不是0,会变为WRAP_CONTENT。

所以,需要再加一层Layout。

mLayout = new LinearLayout(this);
LinearLayout container = new LinearLayout(this);
LayoutInflater.from(this).inflate(R.layout.header, mLayout, true);
container.addView(mLayout);
mListView.addHeaderView(container);

这样才能正常将mLayout的高度设置为0。

?

?

AbsListView的Header不能直接固定大小为0

原文:http://jameszhao84.iteye.com/blog/2186329

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!