安卓集列表视图高度动态 [英] android set listview height dynamically
问题描述
我有 ExpandableListview
在滚动型
,我知道那不是很好,但我有太多,展现唯一的解决办法整个名单是由code。使用设置其高度的LayoutParams
i have ExpandableListview
inside ScrollView
and i know that's not good but i had too, the only solution to show the whole list is by set its height by code using layoutParams
RelativeLayout.LayoutParams PARAMS =新
RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
ListViewData.length());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, ListViewData.length());
这个解决方案是好的,但我不认为我应该给出正确的高度 PARAMS
,那么,有没有办法知道从尺寸实际尺寸阵列的
this solution is good but i can't figure the right height that i should give in the Params
, SO is there a way to know the actual size from the size of the array
编辑:
我想出了,每次我展开一个组列表时的解决方案会改变高度,以适应新的geight
i came up with a solution that everytime i expand a group of the list am gonna change the height to fit with new geight
推荐答案
您的ListView是在这种情况下,有效地不需要即可。你可以在你的适配器的项目,以及循环,只是将它们添加到一个垂直的LinearLayout的滚动型内。
Your ListView is effectively unneeded in this case. You can as well loop over your adapter's items and just add them to a vertical LinearLayout inside your ScrollView.
如果你不想改变很多code的:
In case you do not want to change a lot of code:
替换 ListView.setAdapter
与
LinearLayout ll; //this should be the vertical LinearLayout that you substituted the listview with
for(int i=0;i<adapter.getCount();i++) {
View v = adapter.getView(position, null, null);
ll.addView(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
}
如果您已经使用了OnItemClickListener之后添加视图V = adapter.getView(位置,NULL,NULL);
以下
If you already use an OnItemClickListener add after View v = adapter.getView(position, null, null);
the following
final int position = i;
v.setOnClickListener(new OnClickListener() {
public onClick(View v) {
yourOnItemClickListener.onItemClick(null, v, position, 0);
}
});
在这种情况下,你不必担心在高度的任何错误判断。
In this case you do not have to worry about any miscalculation in the height.
这篇关于安卓集列表视图高度动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!