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 yes,then how?
Is it possible to Adjust height of listview with respect to screen size when it is used with adapter
Asked
Active
Viewed 717 times
2 Answers
1
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.

yedidyak
- 1,964
- 13
- 26
-
Maybe do the first part of code in the Adapter constructor. – David Corsalini May 21 '14 at 10:14
-
am a beginner pls help me :) – user3407787 May 21 '14 at 10:18
-
You need to pass the Context into the adapter, if you don't already have a context there. – yedidyak May 21 '14 at 10:40
0
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?