首页 > 移动平台 > 详细

Android 获取View宽度

时间:2016-06-15 10:49:19      阅读:158      评论:0      收藏:0      [点我收藏+]
/*****************************************************************************
 *                         Android 获取View宽度
 * 说明:
 *     在View默认的构造函数里无法获取到View的宽高,需要采用另外的方式获取。
 *
 *                                           2016-6-15 深圳 南山平山村 曽剑锋
 ****************************************************************************/

一、参考文档:
    If I call getMeasuredWidth() or getWidth() for layout in onResume they return 0
        http://stackoverflow.com/questions/6939002/if-i-call-getmeasuredwidth-or-getwidth-for-layout-in-onresume-they-return-0

二、解决办法:
    this.post(new Runnable() {
         public void run() {
             centerX = getMeasuredWidth()/2;
             centerY = getMeasuredHeight()/2;
             ball = new Ball(centerX, centerY);
         }
    }
    );

 

Android 获取View宽度

原文:http://www.cnblogs.com/zengjfgit/p/5586454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!