ListView with the fixed number of items to display

一笑奈何 提交于 2019-12-23 22:18:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!