Litho
  • Introduction
  • 简介
    • Litho 是什么
    • 动机
    • 使用
  • 快速开始
    • 新手入门
    • 教程
    • 编写 Component
    • 使用 Component
  • 参考
    • Layout Specs
    • Mount Specs
    • Props
    • State
    • Layout
    • Error Boundaries
    • Borders
    • RecyclerCollectionComponent
    • 变换动画
    • 术语
  • 事件处理
    • 总览
    • 触摸处理
    • 可见性处理
  • Sections
    • Sections 是什么
    • Sections 教程
    • GroupSection Specs
    • DiffSection Specs
    • Sections Building Blocks
    • 与UI交互
    • Sections 单元测试
    • Sections 与 Views
    • Services
    • Sections 架构
    • Working Ranges
  • 兼容性
    • Styles
    • Accessbility
    • RTL
  • 测试
    • 总览
    • 单元测试基础
    • 子组件测试
    • 匹配 Props
    • 测试 InjectProps
    • 测试事件处理
    • Espresso
    • 在Android Studio上运行测试
  • 高级指南
    • Recycler
    • 自定义布局
    • TreeProps
    • 增量安装
    • 创建 ComponentTree
  • 架构
    • 代码生成
    • 异步布局
    • 增量安装
    • 铺平 View 结构
    • 回收
  • 附加资源
    • 最佳实践
    • FAQ
  • 工具
    • 调试
    • 开发者选项
  • 更多参与
    • 如何参与
    • 社区展示
    • 资源库结构
Powered by GitBook
On this page
  1. 快速开始

使用 Component

Previous编写 ComponentNext参考

Last updated 7 years ago

生成的组件类为您在组件 Spec 中定义的 Prop 提供了一个简单的构建器。为了在UI中使用生成的组件,您需要一个LithoView,它是一个能够渲染组件的 Android ViewGroup 。

您可以按如下方式指定要由LithoView渲染的组件:

final Component component = MyComponent.create(componentContext)
    .title("My title")
    .imageUri(Uri.parse("http://example.com/myimage")
    .build();
LithoView view = LithoView.create(context, component);

在这个例子中,MyComponent将通过宿主LithoView进行布局,您像用 Android View 一样使用 LithoView 。有关如何在 Activity 中使用 LithoView 的例子,请参阅。

重要提示:本示例中的LithoView如果直接用于 View 层次结构中,将在主线程上同步执行布局计算。有关从主线程执行布局的更多信息,请参阅。

教程
异步布局