我正在尝试使用一组远程图像创建列表视图,并在加载它们时显示占位符图像。
var imageSource = require("image-source");
var imageCache = require("ui/image-cache");
var cache = new imageCache.Cache();
var defaultImageSource = imageSource.fromResource("img-loading”);
cache.enableDownload();
cache.placeholder = defaultImageSource;
cache.maxRequests = 5;
尝试使用fromFile而不是fromResource。
有什么难事吗?
答案 0 :(得分:3)
我不确定您是如何使用pulbic class speech implements Recognizer{
startListening(){
//start the listener
}
@Override
onResult(){
//hear i get my string after a random various amount of time
//(when the recognizer is done with hearing my stuff)
//at this point i want to let the other class know, that im done here
}
}
但是无法直接将ImageCache
对象设置为ImageCache
的来源。为了达到你想要的效果,你必须使用这样的东西(取自http://pstaev.blogspot.com/2016/04/using-nativescripts-imagecache-to-cache.html):
主page.xml
Image
主page.ts
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
navigatingTo="navigatingTo">
<ListView items="{{ images }}">
<ListView.itemTemplate>
<GridLayout>
<Image src="{{ imageSrc }}" stretch="aspectFill" height="100"/>
</GridLayout>
</ListView.itemTemplate>
</ListView>
</Page>
图像item.ts
import observableArray = require("data/observable-array");
import observable = require("data/observable");
import imageItem = require("./image-item");
import pages = require("ui/page");
export function navigatingTo(args: pages.NavigatedData)
{
var page = <pages.Page>args.object;
var model = new observable.Observable();
var images = new observableArray.ObservableArray<imageItem.ImageItem>();
images.push(new imageItem.ImageItem("http://foo.com/bar1.jpg"));
images.push(new imageItem.ImageItem("http://foo.com/bar2.jpg"));
// ...
images.push(new imageItem.ImageItem("http://foo.com/bar100.jpg"));
model.set("images", images);
page.bindingContext = model;
}