> For the complete documentation index, see [llms.txt](https://fujianyi.gitbook.io/litho/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fujianyi.gitbook.io/litho/kuai-su-kai-shi/shi-yong-component.md).

# 使用 Component

生成的组件类为您在组件 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 的例子，请参阅[教程](https://fblitho.com/docs/tutorial)。

> 重要提示：本示例中的LithoView如果直接用于 View 层次结构中，将在主线程上同步执行布局计算。有关从主线程执行布局的更多信息，请参阅[异步布局](https://fblitho.com/docs/asynchronous-layout)。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fujianyi.gitbook.io/litho/kuai-su-kai-shi/shi-yong-component.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
