【问题标题】:Titanium android horizontal scrollable tableviewTitanium android水平可滚动tableview
【发布时间】:2014-02-11 19:37:00
【问题描述】:

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

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

请建议我应该是什么可能的解决方案。谢谢。

【问题讨论】:

  • 你试过 Titanium ScrollableView。那个会水平滚动。
  • 谢谢阿南德。是的,我试过了,但我真正想要的是视图应该只有一个,就像我制作一个 tableview 并定义它的大宽度并添加一些水平滚动条。这有意义吗?

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


【解决方案1】:

我认为你不能让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();

我已经尝试过了,它正在工作。希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 2018-12-10
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    相关资源
    最近更新 更多