PythonIDE Docs
中文
简体中文

滚动 API

ScrollView、ScrollViewReader、滚动方向和定位锚点。

ScrollView / ScrollViewReader。


#ScrollView

签名

text
ScrollView(content=None, axes='vertical', shows_indicators=True, showsIndicators=None)

参数

参数类型说明
contentlist[View] \| View \| None可滚动区域;支持 with ScrollView(): 收集子视图。
axesstrverticalhorizontalboth
shows_indicatorsbool是否显示滚动指示条。

示例

python
import appui

def body():
    with appui.ScrollView(axes="vertical") as sc:
        for i in range(25):
            appui.Text(f"段落 {i}").padding(horizontal=4)
    return sc.padding()

appui.run(body, presentation="sheet")

参阅ScrollViewReaderLazyVStack


#ScrollViewReader

签名

text
ScrollViewReader(content=None, axes='vertical', shows_indicators=True,
                 scroll_to=None, anchor='top', showsIndicators=None, scrollTo=None,
                 children=None)

参数

参数类型说明
content / childrenlist[View] \| None滚动内容。
axesstrScrollView
shows_indicatorsbool是否显示指示器。
scroll_to / scrollTo任意 \| None初始或受控滚动目标,需与子视图 .id(...) 对应。
anchorstr滚动对齐锚点,如 top

示例

python
import appui

def body():
    return appui.ScrollViewReader(
        content=[
            appui.Text("顶部").id("top"),
            appui.Spacer(min_length=400),
            appui.Text("底部锚点").id("bottom"),
        ],
        axes="vertical",
        scroll_to="bottom",
        anchor="top",
    ).padding()

appui.run(body, presentation="sheet")

参阅ScrollViewSpacer