2012-07-22 17 views
9

में विस्तार नहीं कर रहा है मैंने एक एक्सएमएल कोड लिखा है, जहां मैं पैरेंट चौड़ाई फिट करने के लिए एडिटटेक्स्ट का विस्तार करना चाहता हूं। इतना समय बिताने के बाद, मुझे एडिटटेक्स्ट का विस्तार करने का कोई तरीका नहीं मिल रहा है।क्यों EditText fill_parent

<?xml version="1.0" encoding="UTF-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <TableRow 
     android:layout_marginLeft="10dp" 
     android:layout_marginBottom="15dip">   
     <TextView 
      android:text="Comment" 
      android:layout_width="match_parent" 
      android:textStyle="bold" 
      android:padding="3dip" />  
    </TableRow> 

    <TableRow 
     android:layout_marginLeft="10dp" 
     android:layout_marginBottom="15dip">   
     <EditText 
      android:id="@+id/EditText02" 
      android:layout_height="wrap_content" 
      android:lines="5" 
      android:gravity="top|left" 
      android:inputType="textMultiLine" 
      android:scrollHorizontally="false" 
      android:minWidth="10.0dip" 
      android:maxWidth="5.0dip"/> 
    </TableRow> 

    <TableRow 
     android:layout_marginLeft="10dp" 
     android:layout_marginBottom="15dip" 
     android:gravity="center">   
     <Button 
      android:id="@+id/cancel" 
      android:text="Next" />  
    </TableRow> 
</TableLayout> 
</LinearLayout> 

क्या मैं गलत यहाँ बना दिया है:

यहाँ मेरी एक्सएमएल है। क्रिप्या मेरि सहायता करे।

उत्तर

2

प्रत्येक पंक्ति में टेक्स्ट व्यू का एक अतिरिक्त कॉलम जोड़ें।

यह कोड आपकी मदद कर सकता है।

<?xml version="1.0" encoding="UTF-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1" 
    android:orientation="vertical"> 

    <TableRow 
     android:layout_width="fill_parent" 
     android:layout_marginLeft="10dp" 
     android:layout_marginBottom="15dip"> 

     <TextView android:text="" />  

     <TextView 
      android:text="Comment" 
      android:layout_width="match_parent" 
      android:layout_marginRight="10dp" 
      android:textStyle="bold" 
      android:padding="3dip" />  
    </TableRow> 

    <TableRow 
     android:layout_marginLeft="10dp" 
     android:layout_marginBottom="15dip"> 

     <TextView android:text="" />   

     <EditText 
      android:id="@+id/EditText02" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:lines="5" 
      android:gravity="top|left" 
      android:inputType="textMultiLine" 
      android:scrollHorizontally="false" /> 
    </TableRow> 

    <TableRow 
     android:layout_marginLeft="10dp" 
     android:layout_marginBottom="15dip" 
     android:gravity="center"> 

     <TextView android:text="" />   

     <Button 
      android:id="@+id/cancel" 
      android:layout_marginRight="10dp" 
      android:text="Next" />  
    </TableRow> 
</TableLayout> 
</LinearLayout> 
1

गंभीर नहीं है तो गंभीर।

आप अपने EditText की न्यूनतम चौड़ाई (minWidth) से बड़ा यह अधिकतम चौड़ाई (maxWidth) है निर्धारित किया है, और आप इसे एक layout_width विशेषता (आप match_parent करने के लिए सेट चाहिए) नहीं दिया है।

+0

मैं इसे match_parent करने के लिए एक layout_width दिया है android:stretchColumns="0" जोड़ने के लिए, लेकिन कुछ भी बदल रहा है कृपया। – user1462473

+0

'maxWidth' और' minWidth' विशेषताएँ भी हटाएं। – kcoppock

0

मुझे लगता है कि आप LinearLayout

दूसरे से android:orientation विशेषता गुम है अगर यह आप सभी क्या आवश्यकता होती है, यदि आप एक TableLayout उपयोग करने से बचें और केवल android:orientation="vertical" के साथ एक एकल LinearLayout और सभी अन्य तीन View रों का उपयोग कर सकते है यह।

+0

'एंड्रॉइड: अभिविन्यास' अनिवार्य नहीं है। यह http://developer.android.com/reference/android/widget/LinearLayout.html के अनुसार 'क्षैतिज 'पर डिफ़ॉल्ट है। –

8

पुराने की तरह, लेकिन मेरा मानना ​​है कि मेरे पास कुछ जोड़ने के लिए है।

मेरा मानना ​​है कि दस्तावेज (नीचे उद्धृत) के अनुसार layout_width और layout_height सभी tableRow बच्चों के लिए पूर्व-निर्धारित हैं।

इसके बजाय, लेआउट_वेट का उपयोग टेबलरो के अंदर तत्वों की चौड़ाई/ऊंचाई निर्धारित करने के लिए किया जा सकता है। यही है, जब तक कि आप इसे एंड्रॉइड सेट नहीं करना चाहते: ईएमएस संपत्ति और इसे अपने फ़ॉन्ट आकार के आधार पर चौड़ाई दें।

उदाहरण के लिए:

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" > 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:hint="@string/place" 
     android:inputType="textPersonName" > 

     <requestFocus /> 
    </EditText> 

</TableRow> 

यह मेरे लिए उत्पादित एक TableRow भीतर एक पूर्ण स्क्रीन विस्तृत EditText।

एक TableRow के बच्चों layout_width और layout_height एक्सएमएल फ़ाइल में गुण निर्दिष्ट करने की आवश्यकता नहीं है:

यहाँ TableRow की documentation से एक उद्धरण है। TableRow हमेशा उन मानों को क्रमशः MATCH_PARENT और WRAP_CONTENT लागू करता है।

समस्या यह है कि, जैसा कि हम जानते हैं, वास्तव में ऐसा नहीं होता है। मुझे संदेह है कि layout_width को "WRAP_CONTENT" भी ​​प्राप्त होता है।

0

आप edittextview में layout_weight="1" का उपयोग कर सकते हैं।

6

अपने TableLayout

+0

बहुत बढ़िया! यह मेरे लिए सही है !! धन्यवाद – arttioz

0

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/back" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" -->> change to 0dip android:paddingRight="@dimen/activity_horizontal_margin" -->> change to 0dip android:paddingTop="@dimen/activity_vertical_margin" tools:context=".StartUp" >