开发者

how to chain onSizeChanged(),onMeasure(),onDraw() in custom view class

开发者 https://www.devze.com 2023-03-25 13:40 出处:网络
how to chain onSizeChang开发者_StackOverflow社区ed(),onMeasure(),onDraw() in custom view class so I can get parent width amd parent height, so that I can scale my image to be fit exactly into the scre

how to chain onSizeChang开发者_StackOverflow社区ed(),onMeasure(),onDraw() in custom view class so I can get parent width amd parent height, so that I can scale my image to be fit exactly into the screen...kindly give any suitable example


Add this to your activity's onCreate

ViewTreeObserver vto        =   layout.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                You should be able to get the width and height
                over here.

                layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消