android获取屏幕宽高,imageview动态设置宽高

Posted on 2014-07-30 13:39  逍_遥  阅读(1177)  评论(0)    收藏  举报
android获取屏幕的高度和宽度用到WindowManager这个类,两种方法: 
 
1、WindowManager wm = (WindowManager) getContext()
                    .getSystemService(Context.WINDOW_SERVICE);
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();
 
2、WindowManager wm = this.getWindowManager();
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();
 
// 动态设置imageview的宽高
  1. image = (ImageView)findViewById(R.id.ImageView01);  
  2.         //height = image.getHeight();  
  3.         //width = image.getWidth();  
  4.         //Log.d(TAG, "height: " + height);  
  5.         //Log.d(TAG, "width: " + width);  
  6.           
  7.           
  8.         LayoutParams para;  
  9.         para = image.getLayoutParams();  
  10.           
  11.         para.height = 300;  
  12.         para.width = 300;  
  13.         image.setLayoutParams(para);  

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3