在ListView标题视图高度 [英] Header View height in a ListView
问题描述
我正与一个ListView这是一个ListFragment的一部分。我想补充一个头与一个特定/自定义的高度,但它并不重要,我把标题视图的高度,它总是有相同的高度。可以修改ListView的头图高度?
下面的code我用:
header.xml 的
< TextView中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =100dp/>
ListFragment 的
@覆盖
公共无效onActivityCreated(包savedInstanceState){
super.onActivityCreated(savedInstanceState);
TextView的fakeHeader =(TextView中)getActivity()getLayoutInflater()膨胀(R.layout.header,空)。
。getListView()addHeaderView(fakeHeader);
}
在传递空
作为第二个参数膨胀()
,你说有没有与该视图关联的父。这有不幸的副作用,其中的任何布局_
属性使用被忽略为布局_
参数会影响母公司勾画出子视图,而不是直接影响到孩子(像其他意见):这种亲尖戈德斯到的更多详细信息布局_
属性。
您可以使用膨胀(R.layout.header,getListView(),FALSE)
通过在ListView最终将你的头视图的父(注意假称不直接添加视图 - 的ListView
将自动为您做到这一点)
I'm working with a ListView that is part of an ListFragment. I want to add a header with a specific/custom height but it does not matter what I put in the height of the header view, always it has the same height. Is possible to modify the header view height of a ListView?
Below the code I use:
header.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp" />
ListFragment
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
TextView fakeHeader = (TextView)getActivity().getLayoutInflater().inflate(R.layout.header, null);
getListView().addHeaderView(fakeHeader);
}
When you pass in null
as the second parameter to inflate()
, you are saying there is no parent associated with the view. This has the unfortunate side effect where any layout_
attribute you use is ignored as layout_
parameters affect how the parent lays out the child view rather than directly affect the child (like other views): this pro-tip godes into more details on layout_
attributes.
You can use inflate(R.layout.header, getListView(), false)
to pass in the ListView which will eventually the parent of your header view (note the false says to not add the view directly - ListView
will do this automatically for you).
这篇关于在ListView标题视图高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!