布局重量警告嵌套的重量表现不佳 [英] Layout Weight warning Nested weight bad performance

查看:615
本文介绍了布局重量警告嵌套的重量表现不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。现在我得到警告嵌套的重量差performance.I在我的第一个屏幕上只有一个图像和三个按钮。伪卫星给我一些想法。

结果

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@色/的backgroundColor
    机器人:方向=垂直
    机器人:重力=CENTER_HORIZONTAL
    机器人:weightSum =10
    >
    < ImageView的
        机器人:layout_weight =4
        机器人:ID =@ + ID / imageLogo
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =0dip
        机器人:contentDescription =@字符串/图
        机器人:layout_marginLeft =10dp
        机器人:layout_marginTop =20dp
        机器人:SRC =@绘制/ home_screen_logo/>    <的LinearLayout
       机器人:layout_weight =6
       机器人:layout_width =FILL_PARENT
    机器人:layout_height =0dip
    机器人:方向=垂直
    机器人:重力=CENTER_HORIZONTAL
        >        <的LinearLayout机器人:layout_height =0dp的android:layout_width =FILL_PARENT
            机器人:layout_weight =1
            机器人:ID =@ + ID / TEMP>< / LinearLayout中>
    <的ImageButton
        机器人:ID =@ + ID / btnLogin
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:背景=@绘制/登陆
        机器人:contentDescription =@字符串/图
        机器人:layout_weight =1
        />
    <的LinearLayout机器人:layout_height =0dp的android:layout_width =FILL_PARENT
            机器人:layout_weight =1>< / LinearLayout中>
    <的ImageButton
        机器人:ID =@ + ID / btnFbLogin
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
         机器人:背景=@绘制/ btnfb
         机器人:contentDescription =@字符串/图
        />
    <的LinearLayout机器人:layout_height =0dp的android:layout_width =FILL_PARENT
            机器人:layout_weight =1>< / LinearLayout中>
    <的ImageButton
        机器人:ID =@ + ID / btnRegister
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:背景=@绘制/ btnregister
        机器人:contentDescription =@字符串/图/>
< / LinearLayout中>
< / LinearLayout中>

结果
由于提前


解决方案

  

嵌套的权重是不好的性能,因为:


  
  

    

布局权重需要一个窗口小部件被测量两次。当具有非零权重的LinearLayout嵌套在另一个的LinearLayout内具有非零权重,则该测量数成倍增加。


  
  
  

它总是最好使用 RelativeLayouts 并调整根据其他意见的地方你的看法,而无需使用特定的DPI值。


礼遇:<一href=\"http://stackoverflow.com/questions/9430764/why-are-nested-weights-bad-for-performance-alternatives\">Why嵌套的权重坏的表现?替代方案?

I am new to android. Now i get warning for Nested weight bad performance.I have only one image and three buttons in my first screen. PLs give me some idea.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/backgroundColor"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:weightSum="10"
    >


    <ImageView
        android:layout_weight="4"
        android:id="@+id/imageLogo"
        android:layout_width="wrap_content" 
        android:layout_height="0dip"
        android:contentDescription="@string/Img"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/home_screen_logo" />

    <LinearLayout
       android:layout_weight="6"
       android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:orientation="vertical" 
    android:gravity="center_horizontal"
        >

        <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"
            android:id="@+id/temp"></LinearLayout>
    <ImageButton
        android:id="@+id/btnLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/login"
        android:contentDescription="@string/Img"  
        android:layout_weight="1"
        />
    <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"></LinearLayout>
    <ImageButton
        android:id="@+id/btnFbLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
         android:background="@drawable/btnfb"
         android:contentDescription="@string/Img"
        />
    <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"></LinearLayout>
    <ImageButton
        android:id="@+id/btnRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/btnregister"
        android:contentDescription="@string/Img"/>
</LinearLayout>
</LinearLayout>


Thanks in Advance

解决方案

Nested weights are bad for performance because:

Layout weights require a widget to be measured twice. When a LinearLayout with non-zero weights is nested inside another LinearLayout with non-zero weights, then the number of measurements increase exponentially.

It's always better to use RelativeLayouts and adjust your view according to the places of other views without using specific dpi values.

courtesy: Why are nested weights bad for performance? Alternatives?

这篇关于布局重量警告嵌套的重量表现不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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