2013-05-03 23 views
10

私はオプションmeasureWithLargestChild="true"で遊んでいます。私のボタンの1つに大きすぎるテキストがあると、なぜ私のレイアウトが壊れたのか分かりません。私はそれが1/3の基本的なサイズを保つべきだと思うが、彼らは1/6くらい小さくなる。何故ですか?measureWithLargestChildを理解する:なぜレイアウトが壊れるのですか?

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で項目を縮小します、と言います。 measureWithLargestChildtrueに設定されているため、すべてのアイテムの幅は最も左のアイテムと同じです。今、彼らはすべて一緒に親の幅に収まりません。したがって、彼らは縮小されるでしょう。バグがなければ、すべてのアイテムは後で同じ幅になります。しかし、バグのためアルゴリズムはmeasureWithLargestChild属性に従って計算された幅の代わりにオリジナルの(wrap_content)の幅を縮小します。右の2つのアイテムが小さくなったのはこのためです。

+0

誰かがケース2(4件のうち)で収縮した理由を説明してもらえますか?この場合、どのようにスペースがありませんか? – Diffy

関連する問題