атрибут layout_weight в теге

#android

#Android

Вопрос:

Я пытаюсь повторно использовать некоторые компоненты макета в приложении Android с помощью <include> тега. У меня разные макеты портов и земли:

  1. Порт:

     <LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp">
    
        <include layout="@layout/calc_equals_button" a:layout_weight="4"/>
        <include layout="@layout/calc_display"/>
    
    </LinearLayout>
      
  2. Земля:

     <LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp">
    
        <include layout="@layout/calc_equals_button"/>
        <include layout="@layout/calc_display"/>
    
    </LinearLayout>
      

Основное отличие a:layout_weight="4" в том, что я хочу, чтобы мой компонент calc_equals_button был меньше по ориентации порта.

Дело в том, что если я попытаюсь встроить calc_equals_button компонент напрямую, все будет работать нормально, например:

 <LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp">
        <DirectionDragButton
                xmlns:a="http://schemas.android.com/apk/res/android"
                a:id="@ id/equalsButton"
                a:text="="
                a:layout_width="match_parent"
                a:layout_height="match_parent"
                a:layout_weight="4"
                style="@style/control_button_style"
                a:onClick="numericButtonClickHandler"/>

        <include layout="@layout/calc_display"/>

    </LinearLayout>
  

в противном случае — НЕТ.

Вот пример calc_equals_button.xml:

 <DirectionDragButton
    xmlns:a="http://schemas.android.com/apk/res/android"
    a:id="@ id/equalsButton"
    a:text="="
    a:layout_width="match_parent"
    a:layout_height="match_parent"
    style="@style/control_button_style"
    a:onClick="numericButtonClickHandler"/>
  

Ответ №1:

Текущее ограничение заключается в том, что вы должны указать layout_width и layout_height для применения других атрибутов layout_* .

Комментарии:

1. «Текущий», как в нем, будет изменен в ICS?

2. Но как это может помочь решить проблему?

3. @MichellBak Нет, это ограничение все еще присутствует в ICS.

4. @se.solovyev Это решает вашу проблему… В вашем теге include должны быть указаны ширина и высота, чтобы учитывался вес.