2012-02-10 13 views
14

हे मैं ऊंचाई EditText बॉक्स की चौड़ाई का प्रबंधन करने के एंड्रॉयड में प्रोग्राम के रूप में मैं करने की कोशिश की edittext.setWidth(32); और edittext.setEms(50); दोनों काम नहीं कर रहे कृपया मेरी नीचे कोडिंग coze मैं इसे उपयोग कर रहा हूँ गतिशील बनाने के लिए देखना चाहते हैं एंड्रॉयडकैसे EditText बॉक्स ऊंचाई सेट और में प्रोग्राम के रूप में चौड़ाई एंड्रॉयड

private EditText createEditText() 
    { 
     final LayoutParams lparams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); 
     final EditText edittext = new EditText(this); 
     edittext.setLayoutParams(lparams); 
     edittext.setWidth(32); 
     edittext.setEms(50); 
     return edittext; 
    } 

उत्तर

21
private EditText createEditText() 
{ 
    final LayoutParams lparams = new LayoutParams(50,30); // Width , height 
    final EditText edittext = new EditText(this); 
    edittext.setLayoutParams(lparams); 
    return edittext; 
} 

में EditText इस प्रयास करें। मेरे लिए

Display display = getWindowManager().getDefaultDisplay(); 
    int screenWidth = display.getWidth(); 
    int screenHeight = display.getHeight(); 

profile_pic.getLayoutParams().height=(screenHeight/6); 
    profile_pic.getLayoutParams().width=(screenHeight/6); 
+5

कौन सा 'LayoutParams' आयात करने के लिए? – Mann

+2

ViewGroup.LayoutParams आयात करने की आवश्यकता – MRK

10
edittext.getLayoutParams().width=32; 
+0

इसकी ठीक से काम कर धन्यवाद यू इतना –

+6

यह मैं NullPointerExceptions का कारण बनता है धन्यवाद ... :-( – JerabekJakub

6
DisplayMetrics metrics = new DisplayMetrics(); 
WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); 
wm.getDefaultDisplay().getMetrics(metrics); 
final float height = metrics.heightPixels; 

EditText edittext = new EditText(this); 

edittext.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,(int) (height/2))); 
-2

निम्नलिखित कोड का प्रयास करें। उदाहरण के लिए

lparams.width = 32; 
1
RelativeLayout.LayoutParams.width = 32; 
RelativeLayout.LayoutParams.height = 50; 

काम करता है -:

0
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) edittext.getLayoutParams(); 
      params.width = mScreenWidth/5; 
      params.height = mScreenWidth/5; 
      edittext.setLayoutParams(params); 
संबंधित मुद्दे