Titanium android水平可滚动tableview

时间:2014-02-11 19:37:01

标签: android uitableview scroll titanium-mobile horizontal-scrolling

我们可以水平制作一个钛安卓桌面滚动吗。 我试过这个

var scrollAlbums = Ti.UI.createScrollView({
bottom : 10,
backgroundColor:'green',
contentHeight : Ti.UI.SIZE, // add this
contentWidth : Ti.UI.SIZE, // change this
height : 95,
layout : 'horizontal',
showHorizontalScrollIndicator : false,
showVerticalScrollIndicator : true, // should be a visual indication if can scroll
scrollType : 'horizontal',
horizontalWrap : false,
width : Ti.UI.FILL // assuming you need it full width - if not specify a width
});

// Create a TableView.
var aTableView = Ti.UI.createTableView({width:1000,backgroundColor:'red',height:200});

请建议我应该采取什么样的解决办法。谢谢。

1 个答案:

答案 0 :(得分:0)

我认为你无法横向进行tableview滚动。但您可以使用scrollView作为tableView

根据文件:

  

添加到滚动视图的视图将根据大小滚动   内容的可滚动区域。如果可滚动区域符合其滚动视图的大小,则视图将不会滚动。

在Android上,您只能在一个方向(垂直或水平方向)滚动滚动视图,而不能同时滚动两个方向。您可以使用 scrollType属性显式设置滚动方向

来自文档:

  

如果未定义scrollType属性,则滚动视图会尝试   根据一些其他属性推导出滚动方向   已经设定好了。具体来说,如果设置了contentWidth和width   并且彼此相等,或者它们都是相同的   showVerticalScrollIndicator设置为true,然后是滚动方向   设置为“垂直”。如果contentHeight和height都设置了,那么   等于,或者如果它们都设置并且showHorizo​​ntalScrollIndicator是   设置为true,然后滚动方向设置为“水平”。如果   scrollType已设置,它将覆盖推断的设置。

请查看以下示例

var win = Ti.UI.createWindow({
  backgroundColor: 'white',
  exitOnClose: true,
  fullscreen: false,
  title: 'Horizontal ScrollView Demo'
});

var scrollView = Ti.UI.createScrollView({
  contentWidth  : 'auto',
  contentHeight : 'auto',
  scrollType    : 'horizontal',
  showHorizontalScrollIndicator: true
});

var containerView = Ti.UI.createView({
    width       : 2000,
    layout      : 'horizontal',
    height      : 300,
    backgroundColor : '#000'
});

var columns = [];
for(var index=0;index<15;index++){
    columns[index] = Ti.UI.createView({
        width   : 200,
        height  : 200,
        backgroundColor : '#123456',
        left    : 20 
    });
    containerView.add(columns[index]);
}
scrollView.add(containerView);
win.add(scrollView);
win.open();

我试过这个并且它正在工作。希望它对你有所帮助。

相关问题