码迷,mamicode.com
首页 > 移动开发 > 详细

android获取view高度方法

时间:2015-06-11 14:31:26      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

直接用view.getheightMesure获取不到(因为还没绘制出来)

用这个

int w = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		int h = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		imageView.measure(w, h);
		int height = imageView.getMeasuredHeight();
		int width = imageView.getMeasuredWidth();
或者
ViewTreeObserver vto = imageView.getViewTreeObserver(); 
	    vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 
	        public boolean onPreDraw() { 
	        	vto.removeOnPreDrawListener(this);
	            int height = imageView.getMeasuredHeight(); 
	            int width = imageView.getMeasuredWidth(); 
	            return true; 
	        } 
	    }); 

android获取view高度方法

标签:

原文地址:http://www.cnblogs.com/luogang/p/4568822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!