0

这是我的布局,我收到一条警告:"Nested weights are bad for performance"for ImageView. 我怎样才能避免这种情况,我做错了什么?

    <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:orientation="vertical"
android:background="@android:color/white">


<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1.50">

    <ImageView 
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="@drawable/left_top"
        android:layout_weight=".75"  
        android:contentDescription="@string/title" 
        />
     <ImageView 
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_weight="1.25"
        android:contentDescription="@string/title" 
        />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="@drawable/right_top" 
        android:layout_weight="0.50"
        android:contentDescription="@string/title"  />

</LinearLayout>


    <ImageView
        android:id="@+id/imagefirstname"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:contentDescription="@string/app_name"
        android:background="@drawable/logo"
        android:scaleType="center"
        android:layout_gravity="center_horizontal" 
        />


        <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/welcome_title"
        android:textSize="25sp"
        android:layout_gravity="center"
        android:gravity="center"
         /> 

    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight=".75">

    <ImageView 
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@drawable/left_bottom"
        android:layout_weight=".75"
        android:contentDescription="@string/title" 
        />
     <ImageView 
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.25"
        android:contentDescription="@string/title" 
        />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@drawable/right_bottom" 
        android:layout_weight="0.50"
        android:contentDescription="@string/title"  />

</LinearLayout>



</LinearLayout>

我可以知道实现目标的正确方法是什么吗?也许这个问题太基础了,但我没有找到任何合适的解决方案。

请帮帮我。

4

1 回答 1

1

根据 Android 文档:

使用 LinearLayout 的嵌套实例会导致视图层次结构过深。嵌套使用 layout_weight 参数的多个 LinearLayout 实例可能特别昂贵,因为每个子项需要测量两次。这在布局反复膨胀时尤其重要,例如在 ListView 或 GridView 中使用时。

更远 The performance might improve by flattening the layout—make the layout shallow and wide, rather than narrow and deep.

你有一个LinearLayout在另一个里面有布局权重。而不是你可以用来RelativeLayout代替LinearLayout.

仔细阅读文档以获取更多信息。

于 2014-04-25T14:01:31.687 回答