六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 58|回复: 0

android 获取控件大小

[复制链接]

升级  37.33%

34

主题

34

主题

34

主题

秀才

Rank: 2

积分
106
 楼主| 发表于 2013-1-14 17:44:56 | 显示全部楼层 |阅读模式
在获取控件大小的时候,如果控件没有measure过.获取的大小就会是0.
设置控件的属性为invisible或者为gone时,如过经过measure过,同样也会获取到控件的大小.
 
 
                visibleTextView = (TextView)findViewById(R.id.invi);        goneTextView = (TextView)findViewById(R.id.gone);        visibleTextView.setVisibility(View.GONE);        goneTextView.setVisibility(View.INVISIBLE);                int w = View.MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);        int h = View.MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);        visibleTextView.measure(w, h);        goneTextView.measure(w, h);                int visible_width = visibleTextView.getMeasuredWidth();        int visible_height = visibleTextView.getMeasuredHeight();                int gone_width = goneTextView.getMeasuredWidth();        int gone_height = goneTextView.getMeasuredHeight();
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表