Android get programmatically created view's width

前端 未结 5 2140
一生所求
一生所求 2021-02-18 16:48

I have TextView created programmatically, like that:

                TextView mTextView = new TextView(getApplicationContext());

                final LayoutPar         


        
5条回答
  •  無奈伤痛
    2021-02-18 17:31

    In this method you can get the width height of the view..

        @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        int width = mTextView.getWidth();
        int height = mTextView.getHeight();
    }
    

    and define TextView mTextView as global

提交回复
热议问题