你的ListView在這種情況下有效不必要的。您還可以循環使用適配器的項目,並將它們添加到ScrollView中的垂直LinearLayout。
如果你不想改變很多代碼:
與
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);
}
更換ListView.setAdapter
如果您已經使用了OnItemClickListener View v = adapter.getView(position, null, null);
後添加以下
final int position = i;
v.setOnClickListener(new OnClickListener() {
public onClick(View v) {
yourOnItemClickListener.onItemClick(null, v, position, 0);
}
});
在這種情況下,您不必擔心abou t高度的任何錯誤計算。
嘿,你會寫你的解決方案嗎? – yshrsmz