1

私はアンドロイドに不慣れです。ネストされたウェイトのパフォーマンスが悪いという警告が表示されます。最初の画面には画像が1つとボタンが3つしかありません。PLは私にいくつかのアイデアを与えてくれます。


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


前もって感謝します

4

3 に答える 3

6

ネストされたウェイトは、次の理由でパフォーマンスに悪影響を及ぼします。

レイアウト ウェイトでは、ウィジェットを 2 回測定する必要があります。ゼロ以外の重みを持つ LinearLayout が、ゼロ以外の重みを持つ別の LinearLayout 内にネストされている場合、測定の数は指数関数的に増加します。

RelativeLayouts特定の dpi 値を使用せずに、他のビューの場所に従ってビューを使用および調整することを常にお勧めします。

礼儀:ネストされたウェイトがパフォーマンスに悪いのはなぜですか? 代替案?

于 2013-02-06T06:01:21.360 に答える
0

android:weightSum="10"線形レイアウトから を削除してみてください。android:layout_weight="1"

これで、警告が消えたことがわかります!

ボタンやその他のものの重みを線形レイアウトに保つようにしてください!

これで問題が解決することを願っています:)

于 2014-03-26T01:17:45.620 に答える
0

ネストされたウェイトは、次の理由でパフォーマンスに悪影響を及ぼします。

レイアウト ウェイトでは、ウィジェットを 2 回測定する必要があります。ゼロ以外の重みを持つ LinearLayout が、ゼロ以外の重みを持つ別の LinearLayout 内にネストされている場合、測定の数は指数関数的に増加します。

RelativeLayoutを使用し、特定の dpi 値を使用せずに、他のビューの場所に従ってビューを調整することを常にお勧めします。

参照: http://developer.android.com/resources/articles/layout-tricks-efficiency.html

ほとんどの場合、RelativeLayout を使用して、このような高価な測定を回避できます。RelativeLayout では、ビューはその親、RelativeLayout 自体、または他のビューと整列します。

ビューが相互にどのように配置されているかを明確に理解するために、Android SDK の HierarchyViewer パースペクティブを使用してレイアウトのワイヤーフレームをキャプチャできます。

于 2013-02-06T06:10:51.760 に答える