JavaScript Nativescript:使ListView高度等于行的总高度 上下文
我有一个JavaScript Nativescript:使ListView高度等于行的总高度 上下文,javascript,android,listview,nativescript,Javascript,Android,Listview,Nativescript,我有一个listView元素,它通过外部源拉入它的元素。因此,我不能确定会有多少行 因此,我将listView属性height设置为绑定变量,将属性rowHeight设置为常量 但是,如果我将行高乘以列表项的数量,则列表视图的高度总是太高,留下空白 代码 page.xml 输出图像 问题: 正如您所看到的,listView元素比内部元素高出几个像素,尽管rowHeight被设置为35,并且listViewheight属性被设置为35 xlistView元素数组长度 我试过: 将乘法设置
listView
元素,它通过外部源拉入它的元素。因此,我不能确定会有多少行
因此,我将listView
属性height
设置为绑定变量,将属性rowHeight
设置为常量
但是,如果我将行高
乘以列表项的数量,则列表视图
的高度总是太高,留下空白
代码
page.xml
输出图像
listView
元素比内部元素高出几个像素,尽管rowHeight
被设置为35,并且listView
height
属性被设置为35 xlistView
元素数组长度
我试过:
- 将乘法设置为一次性(例如34/36)
- 将乘法设置为半个值(例如34.5、35.5)
- 多值混合匹配
- 删除列表项上的所有填充和边距(现在唯一的CSS是字体样式和
垂直对齐:中间
这可能吗?我在想两个可能的原因
- 在NativeScript中使用DP(也称为设备独立像素)是通过计算当前设备的实际像素和实际设备密度来实现的。当使用硬编码值时,这可能会导致不同的结果,因为不同设备的密度不同,这些计算可能需要一些舍入
- 分离器宽度(约1dp或更小)
import { screen, ScreenMetrics } from "platform";
var mainScreen = screen.mainScreen;
console.log(mainScreen.heightDIPs);
console.log(mainScreen.heightPixels);
console.log(mainScreen.scale);
console.log(mainScreen.widthDIPs);
console.log(mainScreen.widthPixels);
//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));
var size = (e.allowedSelections.length * 35) + (e.allowedSelections.length * 0.9);
pageData.set("userSelectionHeight", size);
import { screen, ScreenMetrics } from "platform";
var mainScreen = screen.mainScreen;
console.log(mainScreen.heightDIPs);
console.log(mainScreen.heightPixels);
console.log(mainScreen.scale);
console.log(mainScreen.widthDIPs);
console.log(mainScreen.widthPixels);