2012-05-23 3 views
2

Вот мой макет, я получаю это сообщение для двух кнопок внизу, хотя я установил вес только для другого виджета в макете, который не является родителем кнопок (виджет messageText). Что я делаю не так? Благодарю.Вложенные веса плохи для производительности

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="horizontal" 
    android:layout_marginTop="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:layout_marginLeft="10dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/status_label" 
     android:textStyle="bold" 
     android:textSize="20dip" 
     android:textColor="#FEFF80"/> 
    <TextView 
     android:id="@+id/statusText" 
     android:layout_marginLeft="10dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/unsent" 
     android:textSize="20dip" 
     android:textColor="#FEFF80"/> 
</LinearLayout> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_marginTop="10dip" 
    android:layout_height="1dip" 
    android:background="#FEFF80"/> 
<TextView 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="11dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/message_number_caption" 
    android:textSize="15dip"/> 
<EditText 
    android:id="@+id/messageNumber" 
    android:inputType="phone" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:layout_marginTop="30dip" 
    android:layout_marginLeft="11dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/message_text_caption" 
    android:textSize="15dip"/> 
<EditText android:inputType="text" 
    android:id="@+id/messageText" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:layout_weight="1.0" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip"/> 
<LinearLayout 
    android:orientation="horizontal" 
    android:layout_marginTop="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:id="@+id/sendButton" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="10dip" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="@string/send_button_label" 
     android:textSize="15dip"/> 
    <Button 
     android:id="@+id/resetButton" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="10dip" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="@string/reset_button_label" 
     android:textSize="15dip"/> 
</LinearLayout> 
</LinearLayout> 

ответ

2

Вы указали редактировать текст (@ + идентификатор/MessageText) с весом 1 - Вы имели в виду, чтобы сделать это, потому что другие виджеты в этой линейной компоновке не имеют веса?

После этого у вас есть linearlayout с двумя кнопками, которые используют вес законно.

N.B. это довольно простой макет, так что вы, наверное, все в порядке. Если бы у вас была более глубокая иерархия с большим количеством макетов и виджетов, вы, скорее всего, заметили бы замедление.

3

Вы не делаете ничего плохого, это просто предупреждение. Механизм просмотра Android интерпретирует ваш XML и создает объекты просмотра. Google решил, что внутри макета есть вложенные веса (то есть вид с атрибутом android:layout_weight), внутри другого макета заставляет механизм представления работать плохо, и они советуют, чтобы вы этого не делали.

Если есть другой способ достижения макета, который вы строите, не используя атрибут andorid:layout_weight, было бы лучше сделать это таким образом. В противном случае ваше представление может загружаться немного медленно.

Смежные вопросы