Chinaunix首页 | 论坛 | 博客
  • 博客访问: 563353
  • 博文数量: 192
  • 博客积分: 3780
  • 博客等级: 中校
  • 技术积分: 1487
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-26 10:11
文章存档

2012年(6)

2011年(160)

2010年(26)

分类: 嵌入式

2011-06-02 09:34:20

Android动态设置控件高度宽度

  1. /**
         * add by derekguo      
         */
     private static final int HVGA_HEIGHT_PIXELS = 480;
        private static final int HVGA_WIDTH_PIXELS  = 320;
      public void adjustFontWidthAndHeight(View view,int direction,int type) {
       LayoutParams linearParams = (LayoutParams) view.getLayoutParams();
          Display display = getWindowManager().getDefaultDisplay();
          int w = Math.max(display.getWidth(), display.getHeight());
          int h = Math.min(display.getWidth(), display.getHeight());
          Log.i(TAG, display.getWidth()+" "+display.getHeight());
          float ratio_w = (float)w/HVGA_HEIGHT_PIXELS;
          float ratio_h = (float)h/HVGA_WIDTH_PIXELS;
          Log.i(TAG, ""+ratio_w);     
          if(direction == 2){
           if(type == 1){
            linearParams.width = (int) (ratio_w*68);
            linearParams.height=(int) (ratio_h*40);
           }else{
            if(type ==2){
             linearParams.height = (int) (ratio_h*200);
            }
           }
          }else{
           if(direction == 1){
            if(type ==1){
             linearParams.width = (int) (ratio_h*80);
             linearParams.height=(int) (ratio_w*65);
            }else{
             if(type ==2){
              linearParams.height = (int) (ratio_w*325);
             }
            }
           }
          }
          view.setLayoutParams(linearParams);        
         }
阅读(2903) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~