How to retrieve the dimensions of a view?

前端 未结 16 1669
小蘑菇
小蘑菇 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:39

    CORRECTION: I found out that the above solution is terrible. Especially when your phone is slow. And here, I found another solution: calculate out the px value of the element, including the margins and paddings: dp to px: https://stackoverflow.com/a/6327095/1982712

    or dimens.xml to px: https://stackoverflow.com/a/16276351/1982712

    sp to px: https://stackoverflow.com/a/9219417/1982712 (reverse the solution)

    or dimens to px: https://stackoverflow.com/a/16276351/1982712

    and that's it.

提交回复
热议问题