2013-05-03 7 views
10

मैं measureWithLargestChild="true" विकल्प के साथ खेल रहा हूं। मुझे समझ में नहीं आता कि मेरा लेआउट कुल क्यों टूटता है, अगर मेरे बटन में से एक पर बहुत बड़ा टेक्स्ट है। मुझे लगता है कि इसे 1/3 के मूल आकार को रखना चाहिए लेकिन वे 1/6 के बारे में छोटे हो जाते हैं। ऐसा क्यों है?माप को समझनाथथर्जेस्ट चाइल्ड: लेआउट क्यों तोड़ता है?

Button layout bug

यहाँ मेरी xml है:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:baselineAligned="false" 
    android:gravity="center" 
    android:orientation="vertical" > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:baselineAligned="false" 
     android:measureWithLargestChild="true" > 
     <Button 
      style="@style/my_style" 
      android:layout_weight="1" 
      android:text="Button123456" /> 
     <Button 
      style="@style/my_style" 
      android:layout_weight="1" 
      android:text="A" /> 
     <Button 
      style="@style/my_style" 
      android:layout_weight="1" 
      android:text="WW" /> 
    </LinearLayout> 
</LinearLayout> 

उत्तर

6

मेरा मानना ​​है कि इस उपाय एल्गोरिथ्म में एक बग है

यहाँ आप कुछ स्क्रीनशॉट देख सकते हैं। LinearLayout.measureHorizontal(int, int) विधि में निम्न टिप्पणी है।

// Either expand children with weight to take up available space or 
// shrink them if they extend beyond our current bounds 

इसे कहते हैं, कलन विधि weight के साथ आइटम हटना होगा अगर वहाँ उनके लिए पर्याप्त स्थान नहीं है। measureWithLargestChild को true पर सेट किया गया है, सभी आइटमों में सबसे बाएं आइटम की समान चौड़ाई है। अब वे सभी एक साथ माता-पिता की चौड़ाई में फिट नहीं हैं। इस प्रकार वे कम हो जाएंगे। यदि कोई बग नहीं था, तो सभी वस्तुओं के बाद एक ही चौड़ाई होगी। लेकिन बग के कारण, measureWithLargestChild विशेषता के अनुसार गणना की गई चौड़ाई की बजाय मूल (wrap_content) चौड़ाई घट जाती है। यही कारण है कि दाईं ओर दो आइटम छोटे हो गए।

+0

क्या कोई यह बता सकता है कि यह 2 (4 मामलों में से) में क्यों छोटा हो गया है। इस मामले में कोई जगह उपलब्ध नहीं है? – Diffy

संबंधित मुद्दे