Pergunta

Here's my layout,I get a warning saying: "Nested weights are bad for performance" for ImageView. How can I avoid this and what am I doing wrong?

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

May I know what is the correct way to achieve my objective? Maybe this question too basic, but i did't find any suitable solution.

Please Help me out.

Foi útil?

Solução

According to Android docs :

Using nested instances of LinearLayout can lead to an excessively deep view hierarchy. Nesting several instances of LinearLayout that use the layout_weight parameter can be especially expensive as each child needs to be measured twice. This is particularly important when the layout is inflated repeatedly, such as when used in a ListView or GridView.

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

You have one LinearLayout inside another with layout weights. Rather than that you could use RelativeLayout in place of LinearLayout.

Have a good read of docs for more information.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top