获取view宽高

方法一:重写activity里的onWindowFocusChanged(boolean hasFocus){

    if(hasFocus){

            //TODO

            view.getMeasureWidth();

            view.getMeasureHeight();

    }

}


方法二:view.post(new Runnable{

    @override

    public void run(){

        //TODO

        view.getMeasureWidth();

        view.getMeasureHeight();

    }

});


方法三:ViewTreeObserver observer=view.getViewTreeObserver();

                observer.addOnGlobalLayoutListener(

                    @Override

                    public void onGlobalLayout(){

                        //TODO

                        view.getMeasureWidth();

                        view.getMeasureHeight();

                        view.getViewTreeObserver.removeOnGlobalLayoutListener(this);

                    }

                );

你可能感兴趣的:(获取view宽高)