Is it possible to Adjust height of listview with respect to screen size when it is used with adapter

后端 未结 2 1708
太阳男子
太阳男子 2021-01-16 18:47

Consider a listview contain 2 images and am using an adapter to make a sequence of them. I wish to set the height of an image as 1/3 of the screen size. Is that possible? If

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 19:19

    Yes. If you are using an adapter to set the items in the ListView, then you can set the size of each view in it as it is created. In getView() in the adapter you can add after you have set up the view:

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    

    Which will give you the actual screen dimensions, then

    view.setHeight(height/3);
    return view;
    

    To return that view.

提交回复
热议问题