0

Android工作室总是说“嵌套权重对性能不利”我用一个技巧创建了这个嵌套(一个带有match_parent,match_parent的容器)

我的问题是:
这是嵌套的吗?我的布局标准吗?或者我只是用那个容器愚弄了android studio?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:weightSum="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Head"
            />
    </LinearLayout>


    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <LinearLayout

           android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:layout_weight="0.7"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="right"
                />

            <Button
                android:layout_weight="0.3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="left"
                />

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Foot"
            />
    </LinearLayout>
</LinearLayout>
4

1 回答 1

1

你所做的只是欺骗棉绒。如果您将真正的父级的方向设置为水平方向,Android Studio 也会警告无用的父级。

然而,虽然嵌套权重可能不利于性能,但除非您使用的每个布局都充满了嵌套权重,否则您可能不会注意到它。如果可以避免,请不要使用它们,但如果您这样做,这并不是世界末日。

于 2018-09-25T13:16:57.963 回答