android - 嵌套权重不利于性能

标签 android android-layout

这是我的布局,我收到了底部 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>

最佳答案

你没有做错任何事,这只是一个警告。 Android View 引擎解释您的 XML 并构建 View 对象。 Google 决定在一个布局内、另一个布局内嵌套权重(即具有 android:layout_weight 属性的 View )会导致 View 引擎性能不佳,他们建议您不要这样做它。

如果有另一种方法可以在不使用 andorid:layout_weight 属性的情况下实现您正在构建的布局,那么最好这样做。否则,您的 View 加载可能会有点慢。

关于android - 嵌套权重不利于性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10726726/

相关文章:

android - 如何使用android.webkit.PluginStub

android - 从磨损接收数据后写.wav为空

android - 按钮应该和最大的一样宽

android - 在谷歌地图项目中膨胀类 fragment 时出错

android - 单击弹出菜单项时如何获取列表项 ID?

java - GridLayout 中的按钮对齐方式

android - 我怎样才能 "meteor run android-device"到我的 meteor 服务器?

android - 不幸的是,Launcher3 已停止在 android studio 中工作错误?

jquery - iScroll - 保留 native 垂直滚动 - 适用于 iOS,不适用于 Android

android - 为警报对话框设置 Android Theme.Light