簡體   English   中英

如何在Titanium中將圖像網格添加到ScrollView

[英]How to add a grid of images to a ScrollView in Titanium

我試圖將兩個圖像的行添加到Titanium中的ScrollView中。 我有一個問題,就是只顯示一行。

我的Alloy代碼如下所示:

 <Alloy> <Window class='container' statusBarStyle='Ti.UI.iPhone.StatusBar.LIGHT_CONTENT'> // Make ios status bar correct color <View height='20' top='0' left='0' backgroundColor='#01B6AC'></View> <View id = 'savedContents' layout='vertical' top='20'> </View> <Require type='view' src='bottomBar' id='bottomBar'/> <Widget id="fa" src="com.mattmcfarland.fontawesome"/> </Window> </Alloy> 

我的控制器代碼如下所示:

 var scrollView = Ti.UI.createScrollView({ contentWidth: 'auto', contentHeight: 'height', showVerticalScrollIndicator: false, showHorizontalScrollIndicator: false, width: '100%', height: 400, top: 0 }); for (i=0; i < venueDetails.length; i++) { row = Ti.UI.createView({ width:'100%', height:150, layout:'composite' }); image1 = Ti.UI.createImageView({ image:'http://www.outnow.io/assets/img/small511by309/'+venueDetails[i]["image1"], width:'50%', height:150, left:0, top:0 }); row.add(image1); if (i+1 < venueDetails.length) { image2 = Ti.UI.createImageView({ image:'http://www.outnow.io/assets/img/small511by309/'+venueDetails[i+1]["image1"], width:'50%', height:150, left:'50%', top:0 }); row.add(image2); } //$.savedContents.add(row); scrollView.add(row); } $.savedContents.add(scrollView); 

如果將行視圖直接添加到$ .savedContents視圖中(按照上面代碼中的注釋行),我將正確地看到所有行(每行兩張圖像)。 如果我通過createScrollView進行此操作,則只會得到一行圖像。 我需要使用scrollView使圖像可滾動。

有人知道我在做什么錯嗎?

默認情況下,layout屬性的值為composite 因此,scrollView具有復合布局,因此您需要為該視圖( row )指定定位屬性或“銷”(頂部,底部,左側,右側和中心)。 在您的代碼中,您僅指定了寬度和高度,因此所有視圖都將在父視圖(ScrollView)中居中。

根據Titanium.UI.View-property-layout參考

復合 (或絕對)。 默認布局。 子視圖的定位基於其定位屬性或“圖釘”(頂部,底部,左側,右側和中心)。 如果未指定定位屬性,則子項居中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM