简体   繁体   English

Titanium Android水平滚动表格视图

[英]Titanium android horizontal scrollable tableview

Can we make a titanium android tableview scroll horizontally. 我们可以使钛金属的android tableview水平滚动。 I tried this 我试过了

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});

Please suggest me what should be the possible solution for that.Thanks. 请建议我应该采取什么解决方案。谢谢。

I think you cannot make a tableview scroll horizontally. 我认为您不能使tableview水平滚动。 But you can use a scrollView as tableView . 但是您可以将scrollView用作tableView

According to the documentation: 根据文档:

Views added to the scroll view will be scrolled based on the size of the scrollable region of content. 添加到滚动视图的视图将根据内容的可滚动区域的大小进行滚动。 If a scrollable region fits within the size of its scroll view, the view will not scroll. 如果可滚动区域适合其滚动视图的大小,则该视图将不会滚动。

On Android, you can scroll a scroll view only in one direction, either vertical or horizontal, and not both at the same time. 在Android上,您只能在一个方向(垂直或水平)上滚动滚动视图,而不能同时在两个方向上滚动。 You can use the scrollType property to set the scroll direction explicitly. 您可以使用scrollType属性来显式设置滚动方向

From Documentation: 从文档:

If the scrollType property is not defined, the scroll view attempts to deduce the scroll direction based on some of the other properties that have been set. 如果未定义scrollType属性,则滚动视图将尝试根据已设置的其他一些属性推导滚动方向。 Specifically, if contentWidth and width are both set and are equal to each other, or if they are both set and showVerticalScrollIndicator is set to true, then the scroll direction is set to "vertical". 具体地说,如果contentWidth和width都设置并且彼此相等,或者如果都设置并且showVerticalScrollIndicator设置为true,则滚动方向设置为“ vertical”。 If contentHeight and height are both set and are equal, or if they are both set and showHorizontalScrollIndicator is set to true, then the scroll direction is set to "horizontal". 如果contentHeight和height都设置并且相等,或者都设置了并且showHorizo​​ntalScrollIndicator设置为true,则滚动方向设置为“水平”。 If scrollType is set, it overrides the deduced setting. 如果设置了scrollType,它将覆盖推断的设置。

Please have a look at the following example 请看下面的例子

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();

I have tried this and it's working. 我已经尝试过了,它正在工作。 Hope it helped you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM