我如何在钛中插入垂直滚动条

How can I insert vertical scrollbar in Titanium

本文关键字:插入 垂直 滚动条      更新时间:2023-09-26

我正在用Titanium构建一个应用程序

现在我想在一个窗口中设置滚动视图,因为这个窗口的内容对设备来说太大了。我想插入一个ScrollView并显示垂直滚动条

所以我在构建这个代码:

<Alloy>
    <Window id="indexWindow" orientation="Titanium.UI.UPSIDE_PORTRAIT"  fullscreen="false">
         <ScrollView id="scrollView" showVerticalScrollIndicator="true"
            showPagingControl= "true" showHorizontalScrollIndicator="true" height="80%" width="80%">
        <View class="container" layout="vertical">
            <!-- title -->
            <Label id="titleDatiAnagrafici" class="labelTitle" ></Label>
            <!-- personal data -->
            <TableView id="form_table" height="Titanium.UI.SIZE">
                <TableViewRow id="name_row" class="row_item" layout="horizontal">
                    <Label id="name_label" class="label" />
                    <Label text="Mario" class="labelData"/>
                    <Label id="surname_label" class="label" left="20px"/>
                    <Label text="Rossi" class="labelData"/>
                </TableViewRow>
                <TableViewRow id="name_row" class="row_item" layout="horizontal">
                    <Label id="address_label" class="label" />
                    <Label text="via Cereate 8, Milano" class="labelData"/>
                </TableViewRow>
                <TableViewRow id="name_row" class="row_item" layout="horizontal">
                    <Label id="phone_label" class="label"/>
                    <Label text="333111222" class="labelData"/>
                </TableViewRow>
            </TableView>

        </View>
        </ScrollView>
    </Window>
</Alloy>

但是我看不到垂直滚动条

必须使用View的height属性。

 <Window id="indexWindow" orientation="Titanium.UI.UPSIDE_PORTRAIT"  fullscreen="false">
     <ScrollView id="scrollView" showVerticalScrollIndicator="true"
        showPagingControl= "true" showHorizontalScrollIndicator="true" height="80%" width="80%">
    <View class="container" layout="vertical" height="2000">
        <!-- title -->
        <Label id="titleDatiAnagrafici" class="labelTitle" ></Label>
        <!-- personal data -->
        <TableView id="form_table" height="Titanium.UI.SIZE">
            <TableViewRow id="name_row" class="row_item" layout="horizontal">
                <Label id="name_label" class="label" />
                <Label text="Mario" class="labelData"/>
                <Label id="surname_label" class="label" left="20px"/>
                <Label text="Rossi" class="labelData"/>
            </TableViewRow>
            <TableViewRow id="name_row" class="row_item" layout="horizontal">
                <Label id="address_label" class="label" />
                <Label text="via Cereate 8, Milano" class="labelData"/>
            </TableViewRow>
            <TableViewRow id="name_row" class="row_item" layout="horizontal">
                <Label id="phone_label" class="label"/>
                <Label text="333111222" class="labelData"/>
            </TableViewRow>
        </TableView>

    </View>
    </ScrollView>
</Window>

默认情况下,视图采用其父视图的大小,因此滚动视图永远不会出现

根据文档,您可以在ScrollView标签中添加以下属性:

showVerticalScrollIndicator="true"

如果你愿意,你也可以用同样的方式添加一个水平条:

showHorizontalScrollIndicator: true

看这里的文档