getWidth和getMeasuredWidth的正解
来源:互联网 发布:“免费淘宝模版代码” 编辑:程序博客网 时间:2024/05/22 02:00
1. 在一個類初始化時,即在構造函數當中我們是得不到View的實際大小的。感興趣的朋友可以試一下,getWidth()和getMeasuredWidth()得到的結果都是0.但是我們可以從onDraw()方法裡面得到控件的大小。
2. 這兩個方法所得到的結果的單位是像素即pixel.
對兩個方法做介紹:
getWidth():得到的是view在父Layout中佈局好後的寬度值,如果沒有父佈局,那麼默認的父佈局是整個屏幕。
getWidth(): View在設定好佈局後整個View的寬度。
getMeasuredWidth(): 對View上的內容進行測量後得到的View內容佔據的寬度,前提是你必須在父佈局的onLayout()方法或者此View的onDraw()方法裡調用measure(0,0);(measure 參數的值你可以自己定義),否則你得到的結果和getWidth()得到的結果一樣。
- getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- Android getWidth和getMeasuredWidth的正解
- (转)Android getWidth和getMeasuredWidth的正解
- jetty/Reference/Jetty.xml
- android中使用哪种方式解析XML比较好
- Android中使用自定义的字体
- Android框架浅析之锁屏(Keyguard)机制原理
- Android中为TextView增加自定义的HTML标签
- getWidth和getMeasuredWidth的正解
- 王垠 fvwm 简明教程
- GONE,VISIBLE和INVISIBLE区别
- 从C++到Objective-c
- update-alternatives学习笔记
- Handler的大致流程
- ActivityGroup或TabActivity中捕获keyBack事件
- ImageView与ImageButton
- Spring Quartz定时详解