2016-12-15 96 views
0

任何人都可以幫我解決這個問題嗎?列表視圖只顯示一行。Nativescript:動態列表視圖只顯示一行

有沒有辦法顯示listview中的所有項目?

XML查看

<ScrollView> 
    <stack-layout id="stackID"> 

    </stack-layout> 
</ScrollView> 

代碼隱藏

var listViewModule = require("ui/list-view"); 
var layout = page.getViewById("stackID"); 

var listView = new listViewModule.ListView(); 
var colors = ["red", "green", "blue"]; 
listView.items = colors; 

layout.addChild(listView); 

截圖

enter image description here

回答

1

兩件事:

  1. 除非你必須;不要在ScrollView中放置一個ListView。 ListViews有自己的scrollview代碼內置。

  2. 如果您必須將一個ListView放入ScrollView,您需要設置ListView的高度,使一切正常工作。 (在這種情況下,也建議您設置ScrollView的大小)。

您的佈局應是

<Page><StackLayout> .... other views .... 
<StackLayout id="stackID"> 
    <!-- ListView dynamically inserted here --> 
</StackLayout> 
</StackLayout></Page> 
+0

感謝隊友! :) – imtg