mirror of
https://github.com/BetterAndroid/Hikage.git
synced 2025-09-05 10:15:37 +08:00
docs: update hikage-core
This commit is contained in:
@@ -404,6 +404,46 @@ inline fun <reified LP : ViewGroup.LayoutParams> Hikage.Performer<LP>.MyCustomVi
|
||||
It would seem tedious to implement such complex functions manually every time.
|
||||
If you want to be able to automatically generate component functions, you can introduce and refer to the [hikage-compiler](../library/hikage-compiler.md) module.
|
||||
|
||||
### Combination and Disassembly Layout
|
||||
|
||||
When building a UI, we usually use reusable layouts as components.
|
||||
|
||||
If you don't want each part to be customized separately using a native custom `View`, you can split the layout logic parts directly.
|
||||
|
||||
Hikage supports splitting layouts into multiple parts and combining them, you can use the `Hikageable` function anywhere to create a new `Hikage.Delegate` object.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// Assume this is your main layout.
|
||||
val mainLayout = Hikageable {
|
||||
LinearLayout(
|
||||
lparams = LayoutParams(matchParent = true),
|
||||
init = {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
) {
|
||||
TextView {
|
||||
text = "Hello, World!"
|
||||
}
|
||||
// Combination sublayout.
|
||||
Layout(subLayout)
|
||||
}
|
||||
}
|
||||
// Assume this is your layout submodule.
|
||||
// Since the upper layout uses LinearLayout,
|
||||
// you can declare LinearLayout.LayoutParams for the sublayout.
|
||||
val subLayout = Hikageable<LinearLayout.LayoutParams> {
|
||||
TextView(
|
||||
lparams = LayoutParams {
|
||||
topMargin = 16.dp
|
||||
}
|
||||
) {
|
||||
text = "Hello, Sub World!"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Layout Factory
|
||||
|
||||
Hikage supports custom layout factories and is compatible with `LayoutInflater.Factory2`.
|
||||
|
@@ -388,6 +388,43 @@ inline fun <reified LP : ViewGroup.LayoutParams> Hikage.Performer<LP>.MyCustomVi
|
||||
|
||||
每次都手动实现这样复杂的函数看起来会很繁琐,如果你希望能够自动生成组件函数,可以引入并参考 [hikage-compiler](../library/hikage-compiler.md) 模块。
|
||||
|
||||
### 组合与拆分布局
|
||||
|
||||
在搭建 UI 时,我们通常会将可复用的布局作为组件来使用,如果你不想每一个部分都使用原生的自定义 `View` 将其分别定制,你可以直接将布局逻辑部分进行拆分。
|
||||
|
||||
Hikage 支持将布局拆分为多个部分进行组合,你可以在任何地方使用 `Hikageable` 函数创建一个新的 `Hikage.Delegate` 对象。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
// 假设这是你的主布局
|
||||
val mainLayout = Hikageable {
|
||||
LinearLayout(
|
||||
lparams = LayoutParams(matchParent = true),
|
||||
init = {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
) {
|
||||
TextView {
|
||||
text = "Hello, World!"
|
||||
}
|
||||
// 组合子布局
|
||||
Layout(subLayout)
|
||||
}
|
||||
}
|
||||
// 假设这是你的布局子模块
|
||||
// 由于上层布局使用了 LinearLayout,所以你可以为子布局声明 LinearLayout.LayoutParams
|
||||
val subLayout = Hikageable<LinearLayout.LayoutParams> {
|
||||
TextView(
|
||||
lparams = LayoutParams {
|
||||
topMargin = 16.dp
|
||||
}
|
||||
) {
|
||||
text = "Hello, Sub World!"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 自定义布局装载器
|
||||
|
||||
Hikage 支持自定义布局装载器并同时兼容 `LayoutInflater.Factory2`,你可以通过以下方式自定义在 Hikage 布局装载过程中的事件和监听。
|
||||
|
Reference in New Issue
Block a user