答案 0 :(得分:0)
您可以在添加后获得行的高度,然后将列表视图的高度更改为3 *高度。在渲染列表之后,您需要完成所有这些操作。
示例:
ListView listView = (ListView) findViewById(R.id.listView);
String[] names = new String[] {"hi", "my", "name", "is", "slim", "shady"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, names);
listView.setAdapter(adapter);
View row = listView.getAdapter().getView(0, null, listView);
row.measure(0, 0);
int rowHeight = row.getMeasuredHeight();
listView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, rowHeight*3));