[英]How to add a grid of images to a ScrollView in Titanium
I am trying to add rows of two images to a ScrollView in Titanium. 我试图将两个图像的行添加到Titanium中的ScrollView中。 I am having a problem in that only one row gets shown.
我有一个问题,就是只显示一行。
My Alloy code looks like this: 我的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>
My Controller code looks like this: 我的控制器代码如下所示:
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);
If I add the row views directly to the $.savedContents view (as per the commented out line in the code above) I see all of the rows correctly (two images per row). 如果将行视图直接添加到$ .savedContents视图中(按照上面代码中的注释行),我将正确地看到所有行(每行两张图像)。 If I do this via a createScrollView I only get one row of images.
如果我通过createScrollView进行此操作,则只会得到一行图像。 I need to use the scrollView to make the images scrollable.
我需要使用scrollView使图像可滚动。
Anyone know what I am doing wrong? 有人知道我在做什么错吗?
By default the layout property has a value composite
. 默认情况下,layout属性的值为
composite
。 So the scrollView has the composite layout, so you need to specify the positioning properties or "pins" (top, bottom, left, right and center) for that view ( row
). 因此,scrollView具有复合布局,因此您需要为该视图(
row
)指定定位属性或“销”(顶部,底部,左侧,右侧和中心)。 In your code you only specified the width and height, so all views will be centered in the parent view (ScrollView). 在您的代码中,您仅指定了宽度和高度,因此所有视图都将在父视图(ScrollView)中居中。
According to Titanium.UI.View-property-layout Reference : 根据Titanium.UI.View-property-layout参考 :
composite (or absolute).
复合 (或绝对)。 Default layout.
默认布局。 A child view is positioned based on its positioning properties or "pins" (top, bottom, left, right and center).
子视图的定位基于其定位属性或“图钉”(顶部,底部,左侧,右侧和中心)。 If no positioning properties are specified, the child is centered.
如果未指定定位属性,则子项居中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.