`
iamzhaozheng
  • 浏览: 159318 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

AbsListView的Header不能直接固定大小为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。

 

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics