2013-05-23 5 views
6

मेरे पास एक टेबल है दो कॉलम और दो पंक्तियों के साथ, दोनों पंक्तियों और अंतिम कॉलम में चौड़ाई के लिए match_parent है लेकिन लेआउट पैरेंट चौड़ाई भर नहीं रहा है, यह स्वयं को कंप्यूटर्स की तरह लपेटता है जैसे wrap_content ।layout_width = matchparent के साथ tableLayout माता-पिता से मेल नहीं खाता

यहाँ कोड है:

<TableLayout android:layout_width="match_parent"> 
    <TableRow android:layout_width="match_parent"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:text="static" /> 
     <EditText 
      android:layout_width="match_parent" 
      android:text="text" /> 
    </TableRow> 

    <TableRow android:layout_width="match_parent"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:text="static2" /> 
     <EditText 
      android:layout_width="match_parent" 
      android:text="text2" /> 
    </TableRow> 
</TableLayout> 

क्या मैं माता-पिता की चौड़ाई होने प्रत्येक पंक्ति के लिए क्या करने की जरूरत?

Ps: जिस स्थान पर मैं काम करता हूं, वह मुझे अपना कोड पोस्ट करने की अनुमति नहीं देता है, इसलिए मैं अपने कोड के जितना संभव हो उतना कोड लिखता हूं। मुझे नहीं पता कि यह सही है, मैं परीक्षण नहीं कर सकता।

उत्तर

20

इस कोड मैं इस Wil आप

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

    <TableRow android:layout_width="match_parent" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:text="static" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:text="text" /> 
    </TableRow> 

    <TableRow android:layout_width="match_parent" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:text="static2" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:text="text2" /> 
    </TableRow> 
</TableLayout> 
+3

'एंड्रॉइड: लेआउट_वेट =" 1 "' मेरे 'टेबलरो' में मेरे लिए चाल है। धन्यवाद! – Alias

1

में मदद करता है भी विचार अगर वहाँ अन्य पंक्तियों जिनकी सामग्री एक TextView युक्त अन्य पंक्तियों से अधिक व्यापक है, वज़न विशेषता अच्छी तरह से काम नहीं करेगा क्योंकि लगता है की कोशिश करो। इस उदाहरण पर विचार:

  • तीसरी पंक्ति सेल हर छोड़ दिया सेल चौड़ाई स्थापित कर रही है:

    <?xml version="1.0" encoding="utf-8"?> 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/diseno" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    
        <TableRow 
         android:id="@+id/tableRow1" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content"> 
    
          <TextView 
           android:id="@+id/nombre" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:text="@string/nombre" /> 
    
           <EditText 
            android:id="@+id/campo1" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:inputType="text" /> 
    
        </TableRow> 
    
        <TableRow 
         android:id="@+id/tableRow2" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" > 
    
         <TextView 
          android:id="@+id/apellidos" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/apellidos" 
          android:layout_weight="1"/> 
    
         <EditText 
          android:id="@+id/campo2" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:inputType="text" 
          android:layout_weight="1" /> 
    
        </TableRow> 
    
        <TableRow 
         android:id="@+id/tableRow3" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" > 
    
         <CheckBox 
          android:id="@+id/tick" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:checked="false" 
          android:text="@string/¿Quieres suscribirte a la página?"/> 
    
        </TableRow> 
    

    तो यह परिणाम है।

  • पहली पंक्ति एडिटटेक्स्ट शुरू होती है जहां बायां सेल समाप्त होता है (लगभग स्क्रीन चौड़ाई के लगभग तीन चौथाई)।
  • दूसरी पंक्ति को प्रत्येक सेल वजन 1 दिया जाता है, इसलिए पंक्ति में दोनों कोशिकाओं को आधा स्क्रीन मापनी चाहिए, लेकिन चूंकि पहला सेल उस चौड़ा है, इसलिए वजन अनुपात में गणना की जाती है, इसलिए यदि आप 50 का वजन निर्धारित करते हैं सही सेल के लिए, आपको कभी भी आधा स्क्रीन नहीं मिलेगी क्योंकि पहला सेल तीसरे सेल की सामग्री से छोटा नहीं हो सकता है।
संबंधित मुद्दे