问题
is there any standard way in Android for creating a list view covering content by width, but with the height big enough for displaying a fixed number of rows?
For example, I would want my scrollable listview to pop up in the middle of a screen/activity displaying exactly 6 items out of 20 at a time.
回答1:
Try this.
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
public boolean setViewValue(View view, Object data, String textRepresentation) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view
.getLayoutParams();
params.height = Math.round(mScreenHeight/ 6);
return true;
}
}
);
回答2:
The solution from wrap_content for a listview's width works ( see getWidestView ). Same thing can be applied for height ( measure a height using fake parent and *6 after )
来源:https://stackoverflow.com/questions/30226186/listview-with-the-fixed-number-of-items-to-display