首页 > 解决方案 > 具有自定义视图的 ConstraintLayout 作为回收站中的项目

问题描述

似乎 aConstraintLayout是 a 的改进版本RelativeLayout。我想知道,如果我有自定义视图(比如说线性布局但不是太嵌套),使用 aConstraintLayout并将这些自定义视图显示在布局中的某个位置,特别是对于 recyclerview 中的项目,这是一种不好的做法吗?

标签: androidperformanceandroid-recyclerviewandroid-viewandroid-constraintlayout

解决方案


我会说是的 - 当您使用 constrainLayout 时,主要目的是保持视图层次结构平坦并避免嵌套视图组。

所以尽量不要将嵌套视图组添加到您的约束布局(如 relativeLayout、线性等)。

使用 constraintLayuout,将您的 customView 从 linearLayout 迁移到 constraintLayout 非常容易,这样做可以保持平面视图层次结构 - 没有额外的计算(如使用android:weightSumand时在 linearLayout 中layout_weight)并且您的布局将加载得更快。


推荐阅读