2012-06-04 109 views
0

我在eclipse代碼中顯示以下規則。這條規則主要關注所有類型的電話。但我的問題是,如果文本更大,就像在這種情況下它正在包裝盒內一樣。有沒有辦法讓文本自動增大,並增加文本?Android eclipse - 使文本框大小增加

TextView rule1 


    //Add Rule 1 
      rule1=new ImageView(this);  
      rule1.setBackgroundResource(R.drawable.rules); 
      if(w<340) 
      { 
       layout_params=new RelativeLayout.LayoutParams(width(310), height(44)); 
       layout_params.leftMargin=width(5); 
       layout_params.topMargin=height(30);   
      }else if(w<=500) 
      {   
       layout_params=new RelativeLayout.LayoutParams(width(469), height(64));    
       layout_params.topMargin=height(40); 
       layout_params.leftMargin=width(6); 
      }else 
      { 
       layout_params=new RelativeLayout.LayoutParams(width(774), height(92)); 
       layout_params.leftMargin=width(13); 
       layout_params.topMargin=height(60); 
      } 
      list_layout.addView(rule1, layout_params); 


      icon6=new ImageView(this);  
     icon6.setBackgroundResource(R.drawable.leader); 
      if(w<340) 
      { 
       layout_params=new RelativeLayout.LayoutParams(width(31), height(33)); 
       layout_params.leftMargin=width(12); 
       layout_params.topMargin=height(39);   
      }else if(w<=500) 
      {   
       layout_params=new RelativeLayout.LayoutParams(width(43), height(44));   
       layout_params.topMargin=height(52); 
       layout_params.leftMargin=width(18); 
      }else 
      { 
       layout_params=new RelativeLayout.LayoutParams(width(57), height(60)); 
       layout_params.leftMargin=width(30); 
       layout_params.topMargin=height(78); 
      } 
      list_layout.addView(icon6, layout_params); 

      rule1 = new TextView(this); 
       rule1.setText("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); 
      rule1.setTextColor(Color.WHITE); 
      rule1.setTextSize(18);  
      rule1.setGravity(Gravity.LEFT); 
      typeFace=Typeface.createFromAsset(getAssets(), "fonts/HelveticaLTStd-Bold.otf"); 
      rule1.setTypeface(typeFace); 
      if(w<340) 
      { 
       rule1.setTextSize(16); 
       layout_params=new RelativeLayout.LayoutParams(width(252), height(30)); 
       layout_params.leftMargin=width(40); 
       layout_params.topMargin=height(39);   
      }else if(w<=500) 
      {   
       layout_params=new RelativeLayout.LayoutParams(width(378), height(40)); 
       layout_params.leftMargin=width(72); 
       layout_params.topMargin=height(52);    
      }else 
      { 
       layout_params=new RelativeLayout.LayoutParams(width(630), height(60)); 
       layout_params.leftMargin=width(120); 
       layout_params.topMargin=height(78);       
      } 
      rule1.setLayoutParams(layout_params); 
      list_layout.addView(rule1); 

回答

0

我想你想要的是WRAP_CONTENT

RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 150); 

您還可以設置TextViewsingleLine如果你喜歡:

TextView.setSingleLine(true);