ListView 不显示

ListView 不显示

我正在开发适用于 ubuntu touch 的应用程序。我有一个包含 listView 的代码。但是当我运行它时,页面只是空的(有一个标题和一个选项卡切换器)。错误在哪里?

import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import QtQuick.XmlListModel 2.0

MainView {

applicationName: "El Wohust"
objectName: "elwohust"

width: units.gu(50)
height: units.gu(75)
XmlListModel {
    id: portals
    source: "http://localhost/feed.xml"
    query: "/portals/item"

    XmlRole { name: "title"; query: "title/string()" }
    XmlRole { name: "pubDate"; query: "pubDate/string()" }
 }

// Here

           Tab {
               title: i18n.tr("2nd list")
               Page {
                   id: subreddits
                   anchors.fill: parent

                   ListView {
                       id: articleList


                       model: portals
                       delegate: ListItem.Subtitled {
                                   text: title
                                   subText: pubDate
                                   progression: true
                                   onClicked: pageStack.push(articleView)
                               }

                   }
               }
}

}

}

XML 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
  <portals>

    <item>
        <title>Karlův most</title>
        <pubDate>Sat, 07 Sep 2010 10:00:01 GMT</pubDate>
    </item>
    <item>
        <title>Sv. Vít</title>
        <pubDate>Sat, 07 Sep 2010 15:35:01 GMT</pubDate>
    </item>

  </portals>

答案1

我认为您anchors.fill: parent也需要 ListView。

答案2

我认为您必须执行以下操作才能使 ListView 完美运行......

Column {
        spacing: units.gu(2)
        anchors.centerIn: parent.Center

        ListView {
            width: page.width
            height: page.height
            model: dictXMLList
            delegate: ListItem.Subtitled {
                text: word
                subText: meaning
                progression: true

            }

        }

相关内容