简体   繁体   中英

View Width and Height get updated only after it is drawn

I am setting a View's Height at an OnTouch event, later in that event I need to get the Height of that view. The problem is that the event needs to end so the View's Height is updated. Because of that the getHeight() method I call during the event, gives an outdated value.

Is there any way to redraw the view before the event ends or to update the View's params?

You should get this values via posting to a handler of your view..

Try this after you change your view.

view.post(new Runnable(){
    public void run() 
    {
        Log.d(TAG, "height:"+view.getHeight()+" width: "+view.getWidth());
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM