zoukankan      html  css  js  c++  java
  • Android初级教程_获取Android控件的宽和高

    转载地址:http://blog.csdn.net/johnny901114/article/details/7839512

     1      //------------------------------------------------方法一
     2         int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
     3         int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
     4         imageView.measure(w, h);
     5         int height =imageView.getMeasuredHeight();
     6         int width =imageView.getMeasuredWidth();
     7         textView.append("\n"+height+","+width);
     8         
     9         
    10         
    11 
    12         //-----------------------------------------------方法二
    13         ViewTreeObserver vto = imageView.getViewTreeObserver();
    14         vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    15             public boolean onPreDraw() {
    16                 int height = imageView.getMeasuredHeight();
    17                 int width = imageView.getMeasuredWidth();
    18                 textView.append("\n"+height+","+width);
    19                 return true;
    20             }
    21         });
    22         //-----------------------------------------------方法三   
    23         ViewTreeObserver vto2 = imageView.getViewTreeObserver();  
    24         vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    25             @Override  
    26             public void onGlobalLayout() {
    27                 imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);  
    28                 textView.append("\n\n"+imageView.getHeight()+","+imageView.getWidth());
    29             }  
    30         }); 
  • 相关阅读:
    git 强制覆盖本地
    .gitignore 配置
    Git fetch和git pull的区别
    时间函数 date strtotime
    page show
    prepare PDO
    Lucene搜索方法总结
    lucene索引日期和数字
    lucene 3.0.2 + 多文件夹微博数据(时间,微博)构建索引
    lucene 使用注意
  • 原文地址:https://www.cnblogs.com/androidxiaoyang/p/2891960.html
Copyright © 2011-2022 走看看