嵌套的权重是不好的性能 [英] Nested weights are bad for performance

查看:154
本文介绍了嵌套的权重是不好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的布局,我得到这个消息在底部的2个按钮,即使我已经设置了重量仅适用于布局外的其他部件,这不是按钮(在MessageText中小部件)的父。我究竟做错了什么?谢谢你。

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
<的LinearLayout
    机器人:方向=横向
    机器人:layout_marginTop =10dip
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>
    <的TextView
        机器人:layout_marginLeft =10dip
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/ status_label
        机器人:文字样式=大胆
        机器人:TEXTSIZE =20dip
        机器人:文字颜色=#FEFF80/>
    <的TextView
        机器人:ID =@ + ID /状态文本
        机器人:layout_marginLeft =10dip
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/未发送
        机器人:TEXTSIZE =20dip
        机器人:文字颜色=#FEFF80/>
< / LinearLayout中>
<的TextView
    机器人:layout_width =FILL_PARENT
    机器人:layout_marginTop =10dip
    机器人:layout_height =1dip
    机器人:背景=#FEFF80/>
<的TextView
    机器人:layout_marginTop =10dip
    机器人:layout_marginLeft =11dip
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=@字符串/ message_number_caption
    机器人:TEXTSIZE =15dip/>
<的EditText
    机器人:ID =@ + ID / messageNumber
    安卓的inputType =手机
    机器人:layout_marginTop =10dip
    机器人:layout_marginLeft =10dip
    机器人:layout_marginRight =10dip
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:layout_marginTop =30dip
    机器人:layout_marginLeft =11dip
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=@字符串/ message_text_caption
    机器人:TEXTSIZE =15dip/>
< EditText上的android:inputType下=TEXT
    机器人:ID =@ + ID / MessageText中
    机器人:layout_marginTop =10dip
    机器人:layout_marginLeft =10dip
    机器人:layout_marginRight =10dip
    机器人:layout_weight =1.0
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =0dip/>
<的LinearLayout
    机器人:方向=横向
    机器人:layout_marginTop =10dip
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>
    <按钮
        机器人:ID =@ + ID / sendButton
        机器人:layout_marginLeft =10dip
        机器人:layout_marginRight =10dip
        机器人:layout_width =0dip
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =0.5
        机器人:文字=@字符串/ send_button_label
        机器人:TEXTSIZE =15dip/>
    <按钮
        机器人:ID =@ + ID / resetButton
        机器人:layout_marginLeft =10dip
        机器人:layout_marginRight =10dip
        机器人:layout_width =0dip
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =0.5
        机器人:文字=@字符串/ reset_button_label
        机器人:TEXTSIZE =15dip/>
< / LinearLayout中>
< / LinearLayout中>


解决方案

您已经指定了一个编辑文本(@ + ID / MessageText中),重量为1 - 你的意思做,因为在直线的其他部件布局没有重量?

然后在下面,你必须与合法使用重量两个按钮的LinearLayout。

N.B。这是一个非常简单的布局,你可能罚款。如果你有更多的布局和部件更深的层次,那么你就更有可能看到一个缓慢的下降。

Here's my layout, I'm getting this message for the 2 buttons in the bottom, even though I have set the weight only for one other widget in the layout, which is not the parent of the buttons (the messageText widget). What am I doing wrong? Thanks.

<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>

解决方案

You've specified an edit text (@+id/messageText) with a weight of 1 - did you mean to do that because the other widgets in that linear layout don't have a weight?

Then below that you have a linearlayout with two buttons that use weight legitimately.

N.B. it's quite a simple layout so you're probably fine. If you had deeper hierarchy with more layouts and widgets then you would be more likely to see a slow down.

这篇关于嵌套的权重是不好的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆