2010-12-01 12 views
24

टेक्स्ट टेक्स्ट के बावजूद मुझे स्क्रीन के अंदर फिट करने के लिए मेरा टेबललाइट नहीं मिल सकता है when the text cell is largeएंड्रॉइड टेबल लेआउट स्वरूपण समस्याएं

यह मेरा टेबललाउट है। एक साधारण दो-पंक्तियां, दो कॉलम तालिका। बाएं कॉलम कक्ष multiline हैं। यदि इन सेलों में से एक का टेक्स्ट दो पंक्तियों में तोड़ने के लिए बड़ा विचार है, तो कॉलम पूरी स्क्रीन भरने के लिए फैली हुई है और दाएं कॉलम स्क्रीन से बाहर धकेल दिए जाते हैं।

क्यों? स्क्रीन के अंदर रहने के लिए मैं पूरी टेबल को कैसे मजबूर कर सकता हूं? किसी भी संकेत का स्वागत है।

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myTableLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<TableRow> 
    <TextView 
     android:text="Account 4 with a very large name to see if it breaks on two or more lines" 
     android:singleLine="false" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </TextView> 
    <TextView 
     android:text="$400.00" 
     android:gravity="right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </TextView> 
</TableRow> 

<TableRow> 
    <TextView 
     android:text="Account 5" 
     android:singleLine="false" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </TextView> 
    <TextView 
     android:text="$400.00" 
     android:gravity="right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </TextView> 
</TableRow> 

</TableLayout> 

कोड लेआउट प्रदर्शित करने के लिए बुनियादी है:

मेरे TableLayout निम्नलिखित है

public class AccountBrowserTest 
    extends Activity 
{ 
    public void onCreate(Bundle savedInstanceState) 
    {  
     super.onCreate(savedInstanceState); 

     this.setContentView(R.layout.accountbrowser_test); 

    } 
} 

उत्तर

32

जोड़ें एंड्रॉयड: stretchColumns और android:shrinkColumnsTableLayout तत्व करने के लिए:

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="1" 
    android:shrinkColumns="1"> 

1 मूल्यों कॉलम आप परिवर्तन होते देखना चाहते हैं।आप निर्दिष्ट कर सकते अधिक है कि एक मूल्य इस तरह:

android:stretchColumns="0,1" 

या आप परिवर्तन सभी इस तरह कॉलम का क्या करना चाहते हैं:

android:stretchColumns="*" 

कृपया विस्तृत जानकारी के लिए यहाँ देखें: http://android-pro.blogspot.com/2010/02/table-layout.html

0

यह अपने बहु कोशिकाओं की चौड़ाई के लिए wrap_content से कोई लेना देना हो सकता है।

आप इसे अधिक स्पष्ट चौड़ाई देने के कुछ तरीकों का प्रयास कर सकते हैं ... यानी width to 0 सेट करना, और सभी कक्षों को layout_gravity = 1 देना। इससे प्रत्येक कॉलम को बराबर मात्रा में चौड़ाई लेनी चाहिए (या यदि आप चाहते हैं कि किसी के मुकाबले ज्यादा वजन हो) तो आप समायोजित कर सकते हैं।

0

अस्वीकरण: मैं लेआउट के साथ वास्तव में अच्छा नहीं कर रहा हूँ, इसलिए मैं केवल कुछ मूल्यों के साथ एक सा आसपास निभाई है, और यह काम करने के लिए लग रहा था (मैं आप का एक अच्छा विवरण नहीं दे सकता क्यों हालांकि):

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/myTableLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TableRow> 
     <TextView 
      android:text="Account 4 with a very large name to see if it breaks on two or more lines" 
      android:singleLine="false" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
     /> 
     <TextView 
      android:text="$400.00" 
      android:gravity="right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.001" 
     /> 
    </TableRow> 

    <TableRow> 
     <TextView 
      android:text="Account 5" 
      android:singleLine="false" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
     /> 
     <TextView 
      android:text="$400.00" 
      android:gravity="right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.001" 
     /> 
    </TableRow> 
</TableLayout> 

यह भी ध्यान दें कि मैंने गतिविधि में इस लेआउट का प्रयास नहीं किया है, मैंने इसे केवल एक्सएमएल संपादक के लेआउट-व्यू में देखा है, लेकिन कम से कम यह ठीक दिखता है।

0

आप टेबललेआउट में कॉलम कॉलम और/या सिकुड़ने में भी कोशिश कर सकते हैं।

8

मैं अपने अनुप्रयोग के साथ एक ही समस्या थी और निम्नलिखित समाधान नहीं मिला:

<TableLayout 
    android:shrinkColumns="0" 
    android:stretchColumns="1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
</TableLayout> 

यह 2 कॉलम के साथ ठीक काम करता है।

5

मैं एक ही समस्या थी और TableLayout तत्व को

android:stretchColumns="0" 

जोड़ने और TextView कि बहुत लंबा था पर

android:layout_width="0dp" 

निर्धारित करके इसे हल।

+2

प्रदान करता है और वास्तव में क्या इसका मतलब यह है? आपने कैसे पता लगाया कि यह समाधान है? – Paul

1

वहाँ अस्थायी ठीक है, कार्य करें:

android:stretchColumns = " (number of actual col) - 1 " 

कोई यहाँ समाधान मेरे मामले में काम किया।

5

टेबल लेआउट के अंदर shrink का उपयोग कॉलम के लिए कॉलम संपत्ति आप चाहते हैं कि उन्हें फिटिंग

सबसे आसान तरीका है:

<TableLayout 
android:shrinkColumns="*"/> 

सभी स्तंभों हटना या आप के बजाय "*", स्तंभ सूचकांक आप हटना चाहता हूँ, जो अपने मामले में हो जाएगा

<TableLayout 
android:shrinkColumns="0,1"/> 

टिप्पणी उस स्तंभ सूचकांक शून्य से शुरू लिख सकते हैं, इसलिए नवीनतम कोड पहले (इंडेक्स = 0) और दूसरा (इंडेक्स = 1) कॉलम को कम करने की अनुमति देता है।

0

आशा इस कोड को आपकी मदद करेगा .. सार्वजनिक वर्ग MainActivity गतिविधि {

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

<TextView 
     android:id="@+id/tv1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="8dp" 
     android:singleLine="false" 
     android:text="Account 4 with a very large \n name to see if it breaks \n on two or more lines" > 
    </TextView> 

    <TextView 
     android:id="@+id/tv2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="8dp" 
     android:text="$400.00" > 
    </TextView> 
</TableRow> 
संबंधित मुद्दे