Determining the size of an Android view at runtime

前端 未结 12 1924
陌清茗
陌清茗 2020-11-22 09:59

I am trying to apply an animation to a view in my Android app after my activity is created. To do this, I need to determine the current size of the view, and then set up an

12条回答
  •  一整个雨季
    2020-11-22 10:19

    This works for me in my onClickListener:

    yourView.postDelayed(new Runnable() {               
        @Override
        public void run() {         
            yourView.invalidate();
            System.out.println("Height yourView: " + yourView.getHeight());
            System.out.println("Width yourView: " + yourView.getWidth());               
        }
    }, 1);
    

提交回复
热议问题