改善布局性能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
试用 Compose 方式
Jetpack Compose 是推荐在 Android 设备上使用的界面工具包。了解如何在 Compose 中使用布局。
布局是 Android 应用中直接影响用户体验的关键部分。如果实现不当,您的布局可能会导致应用占用大量内存,并且界面速度缓慢。Android SDK 包含一些工具,可帮助您发现布局性能方面的问题。借助本文档,您可以尽可能减少占用的内存,实现流畅的滚动界面。
课程
- 优化布局层次结构
- 复杂的网页会延长加载时间,同样,复杂的布局层次结构也会导致性能问题。本文档介绍了如何使用 SDK 工具检查布局并发现性能瓶颈。
- 通过 <include> 重复使用布局
- 如果您的应用界面在多个位置重复某些布局结构,本文档将向您介绍如何创建高效、可重复使用的布局结构,并将其包含在相应的界面布局中。
- 按需加载视图
- 除了将一个布局组件添加到另一个布局之外,您可能希望让所包含的布局仅在 activity 运行后有需要时才可见。本文档介绍了如何通过按需加载部分布局来提升布局的初始化性能。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Improve layout performance\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to work with layouts in Compose. \n[Performance in Compose →](/jetpack/compose/performance) \n\nLayouts are a key part of Android applications that directly affect the user experience. If\nimplemented poorly, your layout can make your app memory-intensive with slow UIs. The Android\nSDK includes tools to help identify problems in your layout performance. With this documentation,\nyou can implement smooth scrolling interfaces with a minimal memory footprint.\n\nLessons\n-------\n\n**[Optimize layout hierarchies](/develop/ui/views/layout/improving-layouts/optimizing-layouts)**\n: In the same way that a complex web page can slow down load time, a complex layout hierarchy\n can also cause performance problems. This documentation shows how you can use SDK tools to\n inspect your layout and discover performance bottlenecks.\n\n**[Reuse layouts with \\\u003cinclude\\\u003e](/develop/ui/views/layout/improving-layouts/reusing-layouts)**\n: If your application UI repeats certain layout constructs in multiple places, this\n documentation shows you how to create efficient, reusable layout constructs and include them\n in the appropriate UI layouts.\n\n**[Load views on demand](/develop/ui/views/layout/improving-layouts/loading-ondemand)**\n: Beyond including one layout component within another layout, you might want to\n make the included layout visible only when it's needed after the activity is running.\n This documentation shows how you can improve your layout's initialization performance by loading\n portions of your layout on demand."]]