//------------------------------------------------方法一(在控件已经绘制完成之后获取)
intw = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
inth = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
imageView.measure(w, h);
intheight =imageView.getMeasuredHeight();
intwidth =imageView.getMeasuredWidth();
textView.append("\n"+height+","+width);
//-----------------------------------------------方法二(在控件尚未出现在屏幕上时获取)
ViewTreeObserver vto = imageView.getViewTreeObserver();
vto.addOnPreDrawListener(newViewTreeObserver.OnPreDrawListener() {
publicbooleanonPreDraw() {
intheight = imageView.getMeasuredHeight();
intwidth = imageView.getMeasuredWidth();
textView.append("\n"+height+","+width);
returntrue;
}
});
//-----------------------------------------------方法三
ViewTreeObserver vto2 = imageView.getViewTreeObserver();
vto2.addOnGlobalLayoutListener(newOnGlobalLayoutListener() {
@Override
publicvoidonGlobalLayout() {
imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
textView.append("\n\n"+imageView.getHeight()+","+imageView.getWidth());
}
});