How to retrieve the dimensions of a view?

前端 未结 16 1670
小蘑菇
小蘑菇 2020-11-22 01:09

I have a view made up of TableLayout, TableRow and TextView. I want it to look like a grid. I need to get the height and width of this grid. The methods

16条回答
  •  不思量自难忘°
    2020-11-22 01:16

    Are you trying to get sizes in a constructor, or any other method that is run BEFORE you get the actual picture?

    You won't be getting any dimensions before all components are actually measured (since your xml doesn't know about your display size, parents positions and whatever)

    Try getting values after onSizeChanged() (though it can be called with zero), or just simply waiting when you'll get an actual image.

提交回复
热议问题