How to retrieve the dimensions of a view?

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

    As F.X. mentioned, you can use an OnLayoutChangeListener to the view that you want to track itself

    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            // Make changes
        }
    });
    

    You can remove the listener in the callback if you only want the initial layout.

提交回复
热议问题