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

后端 未结 2 1707
太阳男子
太阳男子 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.

    0 讨论(0)
  • 2021-01-16 19:23

    Yes, it is possible to set the height. To know how, check the answers to this question: How to Get Device Height and Width at Runtime?

    0 讨论(0)
提交回复
热议问题