如何减少android中具有自定义视图的复杂布局的布局加载时间?

如何减少android中具有自定义视图的复杂布局的布局加载时间?,android,performance,Android,Performance,我有一个活动和一个片段。其中片段将在活动中动态加载。Fragment有大约20个视图,其中大多数是自定义视图。加载片段大约需要3秒钟,这一次只是加载布局,没有任何初始化或功能。我觉得3秒更多,我想把它减少到1秒。实现这一目标的可能途径是什么。 我所做的事情: **删除权重和嵌套布局。 **删除视图中未使用的属性 **展平布局层次结构。 布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

我有一个活动和一个片段。其中片段将在活动中动态加载。Fragment有大约20个视图,其中大多数是自定义视图。加载片段大约需要3秒钟,这一次只是加载布局,没有任何初始化或功能。我觉得3秒更多,我想把它减少到1秒。实现这一目标的可能途径是什么。 我所做的事情: **删除权重和嵌套布局。 **删除视图中未使用的属性 **展平布局层次结构。 布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gauge="http://schemas.android.com/apk/res/com.test.app.testApp"
xmlns:customview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_light_grey" >

<RelativeLayout
    android:id="@+id/top_components_dummy"
    android:layout_width="match_parent"
    android:layout_height="135dp"
    android:orientation="horizontal" >
    <RelativeLayout
        android:id="@+id/ dummy_layout"
        android:layout_width="370dp"
        android:layout_toLeftOf="@+id/host_layout"
        android:layout_height="match_parent" >
        <LinearLayout
            android:id="@+id/dummy_parent"
            android:layout_width="280dp"
            android:layout_height="80dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/water_and_drain_tactile"
            android:orientation="horizontal" >
            <FrameLayout
                android:id="@+id/dummy_parent_water"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_marginLeft="40dp"
                android:layout_marginRight="20dp" >
                <com.test.app.ui.components.CustomView
                    android:id="@+id/level_indicator"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="16dp"
                    android:src="@drawable/xyz" />
                <ImageView
                    android:layout_width="85dp"
                    android:layout_height="4dp"
                    android:layout_gravity="center|bottom"
                    android:layout_marginBottom="20dp"
                    android:background="@drawable/empty_indiactor"
                    android:contentDescription="@string/empty_string"
                    android:visibility="gone" />
            </FrameLayout>
            <FrameLayout
                android:id="@+id/dummy_parent_drain"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="40dp" >
                <com.test.app.ui.components.CustomView
                    android:id="@+id/drain_level_indicator"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="45dp"
                    android:src="@drawable/xyz" />

                <ImageView
                    android:layout_width="85dp"
                    android:layout_height="4dp"
                    android:layout_gravity="top|center"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/empty_indiactor"
                    android:contentDescription="@string/empty_string"
                    android:visibility="gone" />
            </FrameLayout>
        </LinearLayout>
        <TextView
            android:id="@+id/Waterdummy_TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginRight="30dp"
            android:layout_marginTop="10dp"
            android:layout_toLeftOf="@+id/dummyCenter"
            android:text="Water"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textStyle="bold" />
        <View
            android:id="@+id/dummyCenter"
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:background="#00ffffff" />
        <TextView
            android:id="@+id/Draindummy_TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/dummyCenter"
            android:text="Drain"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textStyle="bold" />
    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/host_layout"
        android:layout_width="400dp"
        android:layout_centerHorizontal="true"
        android:layout_height="match_parent" >
        <ImageView
            android:id="@+id/host_Stop_Background"
            android:layout_width="120dp"
            android:layout_height="80dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/xyz"
            android:contentDescription="@string/empty_string" />
        <ImageView
            android:id="@+id/dull_stop_icon"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_above="@+id/host_stop_text"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:contentDescription="@string/empty_string"
            android:scaleType="fitXY"
            android:src="@drawable/xyz" />
        <TextView
            android:id="@+id/host_stop_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="15dp"
            android:text="STOP"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#000000" />

        <RelativeLayout
            android:id="@+id/host_Rate_Layout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_toLeftOf="@+id/host_Stop_Background" >
            <ImageView
                android:id="@+id/host_Rate_Icon"
                android:layout_width="120dp"
                android:layout_height="80dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:background="@drawable/xyz"
                android:contentDescription="@string/empty_string" />
            <TextView
                android:id="@+id/host_rate_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/host_rate_unit_textView"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="-5dp"
                android:gravity="bottom|center_horizontal"
                android:text="1.5"
                android:textAlignment="gravity"
                android:textColor="#000000"
                android:textSize="34sp" />
        </RelativeLayout>
        <ImageView
            android:id="@+id/host_system_Icon"
            android:layout_width="120dp"
            android:layout_height="80dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_toRightOf="@+id/host_Stop_Background"
            android:background="@drawable/host_system_top_tactile"
            android:contentDescription="@string/empty_string"
            android:paddingBottom="18dp"
            android:paddingTop="18dp"
            android:scaleType="fitCenter"
            android:src="@drawable/xyz" />
    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/dull_rate_layout"
        android:layout_width="350dp"
        android:layout_toRightOf="@+id/host_layout"
        android:layout_height="match_parent" >
        <RelativeLayout
            android:id="@+id/dull_rate_layout"
            android:layout_width="175dp"
            android:layout_height="match_parent" >
            <TextView
                android:id="@+id/dull_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="@string/dull_rate"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000000"
                android:textStyle="bold" />
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="130dp"
                android:layout_height="80dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:background="@drawable/xyz" />
            <TextView
                android:id="@+id/dull_rate_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/dull_rate_unit_textView"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="-5dp"
                android:gravity="bottom|center_horizontal"
                android:text="500"
                android:textAlignment="gravity"
                android:textColor="#000000"
                android:textSize="36sp" />
            <TextView
                android:id="@+id/dull_rate_unit_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="15dp"
                android:text="mL/min"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#000000" />
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/salad_layout"
            android:layout_width="175dp"
            android:layout_height="match_parent"
            android:layout_toRightOf="@+id/dull_rate_layout" >
            <TextView
                android:id="@+id/salad_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="@string/salad"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000000"
                android:textStyle="bold" />
            <ImageView
                android:id="@+id/salad_Icon"
                android:layout_width="130dp"
                android:layout_height="80dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:background="@drawable/dull_salad_tactile"
                android:contentDescription="@string/empty_string"
                android:paddingBottom="18dp"
                android:paddingTop="18dp"
                android:scaleType="fitCenter"
                android:src="@drawable/xyz" />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>
<RelativeLayout
    android:id="@+id/midLinear"
    android:layout_width="match_parent"
    android:layout_height="460dp"
    android:layout_below="@+id/top_components_dummy" >
    <TextView
        android:id="@+id/boomSpeed_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="@string/boom_speed"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000"
        android:textStyle="bold" />
    <TextView
        android:id="@+id/boomSpeed_Value_Text"
        android:layout_width="wrap_content"
        android:layout_height="75dp"
        android:layout_below="@+id/boomSpeed_textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-5dp"
        android:gravity="center"
        android:maxLength="3"
        android:text="300"
        android:textColor="@android:color/black"
        android:textSize="50sp"
        android:textStyle="normal" />
    <ImageView
        android:id="@+id/imageView_down"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_alignBottom="@+id/boomSpeed_Value_Text"
        android:layout_marginRight="5dp"
        android:layout_toLeftOf="@+id/boomSpeed_Value_Text"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <ImageView
        android:id="@+id/imageView_up"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_alignBottom="@+id/boomSpeed_Value_Text"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/boomSpeed_Value_Text"
        android:src="@drawable/xyz" />
    <TextView
        android:id="@+id/boom_Speed_Value_Unit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/boomSpeed_Value_Text"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-10dp"
        android:text="mL/min"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#444444" />
    <ImageView
        android:id="@+id/IV_boomSpeed"
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:layout_below="@+id/boom_Speed_Value_Unit"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:hapticFeedbackEnabled="true"
        android:src="@drawable/xyz" />
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="30dp"
        android:layout_toLeftOf="@+id/IV_boomSpeed"
        android:gravity="center_vertical" >
        <ImageView
            android:layout_width="380dip"
            android:layout_height="380dip"
            android:layout_centerInParent="true"
            android:src="@drawable/xyz" />
        <com.test.app.ui.components.CustomView1
            android:id="@+id/circularprogressbar2"
            android:layout_width="345dip"
            android:layout_height="345dip"
            android:layout_centerInParent="true"
            customview:cpb_backgroundColor="#EDEDED"
            customview:cpb_borderColor="#22B7B3"
            customview:cpb_maintitle="@string/time_remaining"
            customview:cpb_progressColor="#22B7B3" />
        <RelativeLayout
            android:id="@+id/clickablearea"
            android:layout_width="180dip"
            android:layout_height="80dip"
            android:layout_alignTop="@+id/circularprogressbar2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dip"
            android:background="#00fff000" >
        </RelativeLayout>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="30dp"
        android:layout_toRightOf="@+id/IV_boomSpeed"
        android:gravity="center_vertical" >
        <ImageView
            android:layout_width="380dip"
            android:layout_height="380dip"
            android:layout_centerInParent="true"
            android:src="@drawable/dialsbg" />
        <ImageView
            android:id="@+id/IV_StopML"
            android:layout_width="120dip"
            android:layout_height="80dip"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="54dp"
            android:src="@drawable/xyz" />
        <TextView
            android:layout_width="100dip"
            android:layout_height="80dip"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="40dp"
            android:layout_marginRight="15dp"
            android:gravity="center"
            android:text="STOP\n ML"
            android:textColor="@android:color/holo_red_dark"
            android:textStyle="bold" />
        <com.test.app.ui.components.CustomView1
            android:id="@+id/circularprogressbar3"
            android:layout_width="345dip"
            android:layout_height="345dip"
            android:layout_centerInParent="true"
            customview:cpb_borderColor="#E7AB0F"
            customview:cpb_progressColor="#e2a000"
            customview:backgroundColor="#EDEDED"
            customview:goal="@string/goal"
            customview:goal_unit="mL"
            customview:goal_value="2800"
            customview:ml_unit="mL"
            customview:rate="@string/rate"
            customview:rate_unit="mL/hr"
            customview:rate_value="700"
            customview:removed_title="@string/removed"
            customview:removed_value="1500" />
        <RelativeLayout
            android:id="@+id/editMLGoal_clickArea"
            android:layout_width="100dip"
            android:layout_height="50dip"
            android:layout_alignStart="@+id/circularprogressbar3"
            android:layout_marginLeft="60dip"
            android:layout_marginTop="210dip"
            android:background="#00fff000" >
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/editMLRate_clickArea"
            android:layout_width="100dip"
            android:layout_height="50dip"
            android:layout_alignEnd="@+id/circularprogressbar3"
            android:layout_marginRight="60dip"
            android:layout_marginTop="210dip"
            android:background="#00fff000" >
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>
<RelativeLayout
    android:id="@+id/RL_DialView2"
    android:layout_width="300dp"
    android:layout_height="190dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:layout_marginBottom="-40dp" >
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="170dp"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <com.test.app.ui.components.CustomView2
        android:id="@+id/gauge_view2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        gauge:isFloat="false"
        gauge:scaleEndValue="400"
        gauge:scaleMaxLimit="350"
        gauge:scaleMinLimit="150"
        gauge:scaleStartValue="70"
        gauge:showLimitText="true"
        gauge:showNeedle="true"
        gauge:showRanges="true"
        gauge:showScale="false"
        gauge:showText="true"
        gauge:textTitle="@string/ven"
        gauge:textUnit="mmHg"
        gauge:textUnitColor="#000000"
        gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
    android:id="@+id/RL_DialView1"
    android:layout_width="220dp"
    android:layout_height="140dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:layout_marginBottom="-20dp"
    android:layout_toLeftOf="@+id/RL_DialView2" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="120dp"
        android:layout_height="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <com.test.app.ui.components.CustomView2
        android:id="@+id/gauge_view1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        gauge:isFloat="false"
        gauge:scaleEndValue="500"
        gauge:scaleMaxLimit="400"
        gauge:scaleMinLimit="-200"
        gauge:scaleStartValue="-300"
        gauge:showLimitText="true"
        gauge:showNeedle="true"
        gauge:showRanges="true"
        gauge:showScale="false"
        gauge:showText="true"
        gauge:textTitle="@string/art"
        gauge:textUnit="mmHg"
        gauge:textUnitColor="#000000"
        gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
    android:id="@+id/RL_DialView4"
    android:layout_width="220dp"
    android:layout_height="140dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:layout_marginBottom="-20dp"
    android:layout_toRightOf="@+id/RL_DialView2" >
    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="120dp"
        android:layout_height="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <com.test.app.ui.components.CustomView2
        android:id="@+id/gauge_view4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        gauge:isFloat="true"
        gauge:scaleEndValue="40"
        gauge:scaleMaxLimit="38"
        gauge:scaleMinLimit="36"
        gauge:scaleStartValue="34"
        gauge:showLimitText="true"
        gauge:showNeedle="true"
        gauge:showRanges="true"
        gauge:showScale="false"
        gauge:showText="true"
        gauge:textTitle="@string/dt"
        gauge:textUnit="\u2103"
        gauge:textUnitColor="#000000"
        gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
    android:id="@+id/RL_DialView3"
    android:layout_width="220dp"
    android:layout_height="140dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:layout_marginBottom="-20dp"
    android:layout_toLeftOf="@+id/RL_DialView1" >
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="120dp"
        android:layout_height="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <com.test.app.ui.components.CustomView2
        android:id="@+id/gauge_view3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        gauge:isFloat="false"
        gauge:scaleEndValue="320"
        gauge:scaleMaxLimit="300"
        gauge:scaleMinLimit="90"
        gauge:scaleStartValue="70"
        gauge:showLimitText="true"
        gauge:showNeedle="true"
        gauge:showRanges="true"
        gauge:showScale="false"
        gauge:showText="true"
        gauge:textTitle="@string/tmp"
        gauge:textUnit="mmHg"
        gauge:textUnitColor="#000000"
        gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
    android:id="@+id/RL_DialView5"
    android:layout_width="220dp"
    android:layout_height="140dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:layout_marginBottom="-20dp"
    android:layout_toRightOf="@+id/RL_DialView4" >
    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="120dp"
        android:layout_height="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <com.test.app.ui.components.CustomView2
        android:id="@+id/gauge_view5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        gauge:isFloat="true"
        gauge:scaleEndValue="17"
        gauge:scaleMaxLimit="15.9"
        gauge:scaleMinLimit="13.1"
        gauge:scaleStartValue="12"
        gauge:showInnerRim="false"
        gauge:showNeedle="true"
        gauge:showRanges="true"
        gauge:showScale="false"
        gauge:showText="true"
        gauge:textTitle="@string/cond"
        gauge:textUnit="mS/cm"
        gauge:textUnitColor="#000000"
        gauge:textValueColor="#000000" />
</RelativeLayout>


使用RelativeLayouts非常昂贵,因为布局视图是一项“复杂”的任务-每次膨胀xml时,膨胀器都必须计算视图之间的关系,这相当昂贵


您应该尽可能多地使用线性布局。这将使事情有点好转。线性布局的膨胀速度要快得多,因为每个视图的关系最多有2个节点。

您听过CustomView的消息吗? 可以直接布局子视图。所以它不需要反复计算。 例如:

<RelativeLayout
    android:id="@+id/RL_DialView2"
    android:layout_width="300dp"
    android:layout_height="190dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:layout_marginBottom="-40dp" >
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="170dp"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:scaleType="fitXY"
        android:src="@drawable/xyz" />
    <com.test.app.ui.components.CustomView2
        android:id="@+id/gauge_view2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        gauge:isFloat="false"
        gauge:scaleEndValue="400"
        gauge:scaleMaxLimit="350"
        gauge:scaleMinLimit="150"
        gauge:scaleStartValue="70"
        gauge:showLimitText="true"
        gauge:showNeedle="true"
        gauge:showRanges="true"
        gauge:showScale="false"
        gauge:showText="true"
        gauge:textTitle="@string/ven"
        gauge:textUnit="mmHg"
        gauge:textUnitColor="#000000"
        gauge:textValueColor="#000000" />
</RelativeLayout>

这在您的布局中是5倍。 将RelativeLayout更改为带有CustomView2Layout的
图像,该图像从
视图组扩展而来。
然后覆盖测量上的
(int-widthMeasureSpec,int-heightMeasureSpec)
在线布局(布尔值更改,int-left,int-top,int-right,int-bottom)

不过。当您使用CustomView时,它可以准确地知道其子对象的位置(和大小),速度会快得多

了解有关CustomView的更多信息,请访问: 或 GitHub示例

我们还可以查看介质。

您可以查看指南:

  • 避免嵌套的
    视图组
    。您应该使您的
    布局
    尽可能低层次
  • 使用LinearLayout的嵌套实例可能会导致视图层次过深。此外,嵌套多个使用layout_weight参数的LinearLayout实例可能特别昂贵,因为每个子项都需要测量两次。当布局反复膨胀时,如在ListView或GridView中使用时,这一点尤为重要

  • 在布局文件上运行lint工具以搜索可能的视图层次结构优化始终是一种良好的做法

  • 使用
    ViewStub

  • 有时布局可能需要很少使用的复杂视图。无论是项目详细信息、进度指示器还是撤消消息,都可以通过仅在需要时加载视图来减少内存使用并加快渲染速度


    向我们展示您的xml,也许我们可以帮助您。不必调用findViewById应该是一个不错的选择answer@Nanoc请你详细说明你想说什么。在这里完成:@Nanoc谢谢。我来看看。谢谢。之前使用的是LinearLayout,但这需要太多嵌套才能创建所需的UI。所以,嵌套布局同样昂贵。