【发布时间】:2017-11-15 06:45:37
【问题描述】:
我创建了一个包含图像的列表视图,当向下滚动时会自动请求新项目。我正在使用 Image 组件来显示来自 url 源的图像。问题是图像一旦加载就不会缓存在内存中。当我向下滚动时我可以看到它们,但是当我返回时我必须等待它们再次加载。有没有办法来解决这个问题?图像组件有一个属性缓存,但它没有做任何改进。我知道在 Android 中这是以完全相同的方式完成的,并且一旦下载,图像就会保存在内存中。 这是一个示例代码:
ApplicationWindow {
visible: true
width: 800
height: 600
id: rootId
property url fullImageUrl
property string tag : "windsurfing"
XmlListModel{
id : modelId
namespaceDeclarations: "declare namespace media = 'http://search.yahoo.com/mrss/';"
source: "http://api.flickr.com/services/feeds/photos_public.gne?format=rss2&tags="+tag
query: "//item[title and media:thumbnail and media:content]"
XmlRole{name:"fullImage"; query:"media:content/@url/string()" }
}
TextField{
id : userValueId
font.pointSize: 14
width: parent.width
height : implicitHeight
placeholderText: "Enter a Flickr Tag"
onEditingFinished: tag = text
}
ListView{
id : listViewId
anchors.fill: parent
anchors.topMargin: userValueId.height + 10
Layout.minimumWidth: 400
Layout.maximumWidth: parent.width - 50
model: modelId
delegate: delegateId
}
Component{
id: delegateId
Rectangle{
id :itemId
height : 300
width : 500
Image{
id : imageId
source : fullImage
anchors.fill: parent
fillMode: Image.Stretch
cache: true
}
}
}
}
【问题讨论】:
标签: image qt listview caching qml