【问题标题】:ConstraintLayout performance - Guidelines vs MarginsConstraintLayout 性能 - 指南与边距
【发布时间】:2023-03-13 02:25:01
【问题描述】:

我在大部分布局中都使用 ConstraintLayout,我想知道在性能方面的最佳做法是什么:

  1. 使用指南作为视图的限制,包括作为边距限制。

示例:总共 4 个guidelines,没有margins

guideline picture

  1. 使用视图边距会导致间距不准确,因为我需要插入任意数量的 dps。

示例:总共 2 个guidelines,2 个margins (top + bottom)

android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"

margins picture

如果您有其他选择,我很乐意阅读。 另外,我想知道如何跟踪这样的布局配置的性能(你在哪里看过/你用什么来给我答案)。

谢谢。

【问题讨论】:

    标签: android performance android-constraintlayout


    【解决方案1】:

    在这种情况下,您可以在没有指南的情况下获得相同的结果。 ConstraintLayout 中可以使用百分比尺寸。

    只需将“layout_constraintHeight_default”属性设置为“percent”(使用百分比单位),并使用“layout_constraintHeight_percent”设置百分比。 (宽度相关的属性也可用)

    关于 4 个小部件之间的布局性能,以及 2 个小部件和 2 个约束(边距)。我相信后者会做得更好,因为它需要更小的布局来渲染。 但是,在这种情况下,差异是微不足道的。

    【讨论】:

    猜你喜欢
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2020-08-18
    • 1970-01-01
    相关资源
    最近更新 更多