Android:如何获得自定义视图的高度和宽度? [英] Android: How to get a custom View's height and width?
本文介绍了Android:如何获得自定义视图的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何根据父视图调整 Android 视图的大小尺寸
我如何使用 getMeasuredWidth()
和 getMeasuredHeight
?它总是返回 0.这与 getHeight()
和 getWidth()
有什么区别?
how do I use getMeasuredWidth()
and getMeasuredHeight
? It always returns 0. what is the diffrence between this and getHeight()
and getWidth()
?
推荐答案
刚刚得到一个获取自定义视图高度和宽度的解决方案:
Just got a solution to get height and width of a custom view:
@Override
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld){
super.onSizeChanged(xNew, yNew, xOld, yOld);
viewWidth = xNew;
viewHeight = yNew;
}
它在我的情况下有效.
这篇关于Android:如何获得自定义视图的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文