【发布时间】:2017-03-22 18:39:04
【问题描述】:
上下文
我有一个listView 元素,它通过外部源引入其元素。因此我无法确定会有多少行。
因此,我将listView 属性height 设置为绑定变量,并将rowHeight 属性设置为常量。
但是,如果我将rowHeight 乘以列表项的数量,listView 的高度总是太大而留下空白空间。
代码
page.xml
<StackLayout class="group-meta-active" visibility="{{ userCanSelect ? 'visible' : 'collapsed' }}" ontap="teamSelect">
<Label text="Selection" class="group-meta-active-team-label" />
<Label text="{{ selectionName || '' }}" id="{{ selectionId || 0 }}" visibility="{{ selectionId ? 'visible' : 'collapsed'}}" class="group-meta-active-team-name" />
<Label text="Tap To Decide" visibility="{{ selectionId ? 'collapsed' : 'visible'}}" class="group-meta-active-team-decide" />
<ListView items="{{ userAllowedSelections }}" height="{{ userSelectionHeight }}" class="list-clubs" itemTap="selectTeam" rowHeight="35" visibility="{{ selectionSelect ? 'visible' : 'collapsed' }}">
<ListView.itemTemplate>
<StackLayout orientation="horizontal" class="list-clubs-cont">
<Label text="{{ clubName || 'Loading...' }}" textWrap="false" class="list-clubs-label" />
<Label text="vs" textWrap="false" class="list-clubs-vs" />
<Label text="{{ clubOpponent || 'Loading...' }}" textWrap="false" class="list-clubs-opp" />
</StackLayout>
</ListView.itemTemplate>
</ListView>
</StackLayout>
page.js
//When setting page variables; e is the retrieved object;
//e.allowedSelections is an array
pageData.set("userAllowedSelections", (e.allowedSelections));
pageData.set("userSelectionHeight", (e.allowedSelections.length * 35));
输出图像
问题
如您所见,listView 元素比内部元素高几个像素,尽管 rowHeight 设置为 35,listView height 属性设置为 35 x listView 元素数组长度。
我试过了:
- 将乘法设置为一次性(例如 34/36)
- 将乘法设置为半值(例如 34.5、35.5)
- 与多个值混合匹配
- 删除列表项上的所有填充和边距(现在唯一的 CSS 是字体样式和
vertical-align: middle
这可能吗?
【问题讨论】:
标签: javascript android listview nativescript