Android的:如何获得自定义视图的高度和宽度? [英] Android: How to get a custom View's height and width?
本文介绍了Android的:如何获得自定义视图的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/2159320/how-to-size-an-android-view-based-on-its-parents-dimensions">How大小在Android查看基于其母公司的尺寸
我如何使用 getMeasuredWidth()
和 getMeasuredHeight
?它总是返回0。这是什么的diffrence和的getHeight()
和的getWidth()
?
how do I use getMeasuredWidth()
and getMeasuredHeight
? It always returns 0. what is the diffrence between this and getHeight()
and getWidth()
?
推荐答案
对不起,这个问题已经被问。我找到了答案在这里 - <一个href="http://stackoverflow.com/questions/2159320/how-to-size-an-android-view-based-on-its-parents-dimensions">How大小在Android查看基于其母公司的尺寸
Sorry, this question was already asked. I found the answer here - How to size an Android view based on its parent's dimensions
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
this.setMeasuredDimension(parentWidth, parentHeight);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
这篇关于Android的:如何获得自定义视图的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文