我正在为Android/I设计一个视图,我需要设计一个时间选择器(水平)。我已经设计了水平视图,并在其中输入值。

但是不知道如何选择箭头下的值。以及最后一个数字将如何居中(在箭头下)。请指点一下。
代码:
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'});
var scrollAlbums = Ti.UI.createScrollView({
bottom: 10,
contentHeight: Ti.UI.SIZE,
contentWidth: Ti.UI.SIZE,
height: 95,
layout: 'horizontal',
showHorizontalScrollIndicator: false,
showVerticalScrollIndicator: true,
scrollType: 'horizontal',
horizontalWrap: false,
width: Ti.UI.FILL
});
var data=[];
var circle=[];
for(var i=0;i<20;i++){
circle[i] = Titanium.UI.createLabel({
text:i,
height:50,
width:50,
borderRadius:25,
backgroundColor:'#336699'});
scrollAlbums.add(circle[i]);
}
win1.add(scrollAlbums);发布于 2015-03-04 19:12:09
我修改了你的代码,在滚动结束时记录中间的数字:
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'});
var scrollAlbums = Ti.UI.createScrollView({
bottom: 10,
contentHeight: Ti.UI.SIZE,
contentWidth: Ti.UI.SIZE,
height: 95,
layout: 'horizontal',
showHorizontalScrollIndicator: false,
showVerticalScrollIndicator: true,
scrollType: 'horizontal',
horizontalWrap: false,
width: Ti.UI.FILL
});
var circleWidth = 50;
function pick(e) {
if (e.type === 'dragend' && e.decelerate) {
return;
}
console.info('Number: ' + Math.round((e.source.contentOffset.x + (e.source.size.width / 2)) / circleWidth));
}
scrollAlbums.addEventListener('scrollend', pick);
scrollAlbums.addEventListener('dragend', pick);
var data=[];
var circle=[];
for(var i=0;i<20;i++){
circle[i] = Titanium.UI.createLabel({
text:i,
height:circleWidth,
width:circleWidth,
borderRadius:circleWidth/2,
backgroundColor:'#336699'});
scrollAlbums.add(circle[i]);
}
win1.add(scrollAlbums);
win1.open();您需要同时监听scrollend和dragend,因为只有在dragend减速的情况下,scrollend才会触发。然后,用scrollView的偏移量加上其总宽度的一半和圆的宽度,就可以计算出中间的数字。
但就像罗宾说的那样,你最好使用ScrollableView,使用hitRect和clipViews,不仅显示选定的页面(编号),还显示其中的几个左右部分。
https://stackoverflow.com/questions/28830943
复制相似问题