Android 中哪种嵌套布局顺序最有效

发布于 2024-10-24 12:59:44 字数 374 浏览 2 评论 0原文

我认为我在 Android 中从未真正嵌套过超过三层的布局(RelativeLayoutLinearLayoutFrameLayout)。我没有考虑也使用 ListView 的自定义布局的列表项,而只是活动的正常布局。

不过,就这一点而言,我正在与另一位开发人员讨论我们正在讨论的某个布局的嵌套布局,他似乎认为即使是一些嵌套布局也会确实降低性能。我认为有一些道理,但不可能那么多。

有没有人对此有更专业的方法?有什么意见吗?观点?

谢谢。

对于那些在 Google 上找到的人来说,更新: 下面的第一个答案是一个很好的资源。看起来很多,人们似乎会跳过这样的答案,但请检查一下。非常有价值。

I don't think I have really ever nested more than about three levels worth of Layouts (RelativeLayout, LinearLayout, FrameLayout) in Android. I am not thinking about list items which also use a custom layout for ListView but just normal layouts for an activity.

To the point though, I was chatting with another developer about nesting layouts for a certain layout we were discussing and he seemed to think that even a few nested layouts really slowed down performance. I figured there is some truth but it cant be that much.

Does anyone have a more expert approach to this? Any input? Opinion?

Thanks.

UPDATE for those who found on Google:
The first answer below is a great resource. It looks like a lot and people seem to skip over answers like that but please check it out. Very valuable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

牵你的手,一向走下去 2024-10-31 12:59:45

我还没有做过任何适当的测试来支持这一点,不过,我相信 android 的设计是使用嵌套布局来为用户提供足够的 UI,它实际上是支持多个屏幕的唯一方法,所以我不会真正担心哪个是最有效的,只是它看起来应该是这样。

任何其他类型的不良编程实践可能会对效率产生比布局嵌套更大的影响。

I havent done any proper testing to support this, still, I believe that android was design to use nesting Layouts in order to provide adequate UI's to the user, its practically the only way to support multiple screens so I wouldn't really worry about which is the most efficient, just that it looks the way it should.

Any other kind of bad programming practice would probably have a bigger effect in efficiency than layout nesting.

陌伤浅笑 2024-10-31 12:59:45

例如,当您对 ListView 中的每个项目使用这样的布局时,差异将更加重要。希望这个简单的示例向您展示了了解布局是学习如何优化 UI 的最佳方法。

The difference will be much more important when you use such a layout for every item in a ListView for instance. Hopefully this simple example showed you that getting to know your layouts is the best way to learn how to optimize your UI.

-黛色若梦 2024-10-31 12:59:45

无法给您完整的答案,但 Romain Guy 明确指出,嵌套的relativelayouts 具有指数级的测量时间。

请观看38:08 处的视频

Can't give you a full answer, but Romain Guy has specifically stated that nested RelativeLayouts have an exponential time for measurement.

See video here at 38:08 mark

雨的味道风的声音 2024-10-31 12:59:45

实际上它们都基于同一类..
但根据我的说法,最好使用如下:

<RelativeLayout>
    <LinearLayout>
        <at> here we just create nested more as we wont></at>
    </LinearLayout>
</RelativeLayout>

actually all of them are based on the same class..
but it would be better to use according to me as follows:

<RelativeLayout>
    <LinearLayout>
        <at> here we just create nested more as we wont></at>
    </LinearLayout>
</RelativeLayout>
姐不稀罕 2024-10-31 12:59:44

我想这没有什么灵丹妙药,但我会给你一些提示:

1) 尝试使用 android sdk 提供的工具。

我倾向于使用 hierarchyviewerlayoutopt 试图减少 View 的使用量和树的高度。

2) 阅读 Romain Guy 关于 的帖子
这些标签不经常使用,但它们提供了极快的速度“黑客”。

3) 使用dmtracedump并测量膨胀视图需要多长时间。

您可以检查膨胀视图需要多长时间 。看法。获取一个充气机并测量为每个选项充气所需的时间。

I guess there is no silver bullet for this but I will give you some tips:

1) Try using the tools provided with the android sdk.

I tend to analyze my layouts with hierarchyviewer and layoutopt trying to reduce the amount of View used and the height of the tree.

2) Read Romain Guy's posts about <include>, <merge> and <ViewStub>
These tags are not used often but they provide great speed "hacks".

3) Use dmtracedump and measure how long does it take to inflate a view.

You can check how long it takes to inflate a view. Get an inflater and measure how long it takes to inflate each of your options.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文