I have a ListView static height with the 5th item . The lines in these item can be of different lengths and depending on this change the height of the item . Sometimes it turns out that in the height of the ListView all 5 item do not fit and a scroll appears. It is necessary to determine how much item fit into the specified ListView size, and the rest not to display.

  • 3 times read neche not understood =) - Gorets
  • some really incomprehensible turned out to be. reformulated the question)) - tim_taller
  • I still do not understand the problem, it may be easier for you to use 5 TextView. This part is not clear. "It is necessary to determine how many items fit in size, and the rest do not display." - the rest and so will not be displayed .. =) - Gorets
  • unless in the designer it is not visible to what size you stretch it? - Gorets
  • even if using TextView . I have a specific area with a given height to display these TextView . the information in the TextView will load automatically and it turns out that they can swell in height. and now if all these 5 TextView do not fit into my very specified area - will some of them not be displayed? - tim_taller 1:01 pm

1 answer 1

Before adding a view to the ListView you need to call View.measure(int, int) , in fact it initiates the onMeasure(int, int) call, by overloading it you can find out the dimensions that the onMeasure(int, int) will have when it is displayed. Then you have to decide whether to add it to the list or not.

If you do not manually call measure() then onMeasure will be called after adding the control, which in this case is not appropriate.