【问题标题】:Activity indicator in Titanium not workingTitanium 中的活动指示器不工作
【发布时间】:2012-12-28 18:20:08
【问题描述】:

我想使用 Titanium 在我的屏幕上显示一个活动指示器,但它没有显示任何结果。它没有显示任何进展迹象。

这是我的代码:

var actInd = Titanium.UI.createActivityIndicator();

actInd.message = 'Please wait...';
//message will only shows in android.

var self = Ti.UI.createWindow({
    title : "About",
    navBarHidden : false,
    barColor : "#50b849",
    backgroundColor : "#2d2d2d",
});
self.add(actInd);
actInd.show();
self.orientationModes = [Titanium.UI.PORTRAIT];

var text = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "info.txt").read();

var infoText = Ti.UI.createTextArea({
    width : "100%",
    height : "100%",
    color : "#fff",
    backgroundColor : "#2d2d2d",
    value : text,
    editable : false,
    scrollable : false,
    font : {
        fontWeight : 'bold',
        fontSize : 20,
        fontFamily : 'Helvetica Neue'
    },
    textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER,
    autoLink : Ti.UI.AUTODETECT_LINK
});

infoText.addEventListener("click", function() {
    Ti.Platform.openURL("http://tellusanotherone.org/c2p");
});

var scrollView = Ti.UI.createScrollView({
    width : "100%",
    height : "100%",
    verticalBounce : true,
    scrollType : "vertical",
});
scrollView.add(infoText);
self.add(infoText);

return self;

提前致谢。

【问题讨论】:

  • 尝试将这两行self.add(actInd); actInd.show(); 放在return self; 的上方,看看是否有效。或者尝试设置活动指示器的位置,即顶部、左侧等。

标签: javascript android titanium-mobile activity-indicator


【解决方案1】:

只需创建文件 (lib/indicator.js) 并在其中添加以下代码

function createIndicatorWindow(args) {
    var width = 180,
        height = 50;

    var args = args || {};
    var top = args.top || 140;
    var text = args.text || 'Loading ...';

    var win = Titanium.UI.createWindow({
        height:           height,
        width:            width,
        top:              top,
        borderRadius:     10,
        touchEnabled:     false,
        backgroundColor:  '#000',
        opacity:          0.6
    });

    var view = Ti.UI.createView({
        width:   Ti.UI.SIZE,
        height:  Ti.UI.FILL,
        center:  { x: (width/2), y: (height/2) },
        layout:  'horizontal'
    });

    var style;
    if (Ti.Platform.name === 'iPhone OS') {
        style = Ti.UI.iPhone.ActivityIndicatorStyle.PLAIN;
    } else {
        style = Ti.UI.ActivityIndicatorStyle.DARK;
    }

    var activityIndicator = Ti.UI.createActivityIndicator({
        style : style,      
        height : Ti.UI.FILL,
        width : 30
    });

    var label = Titanium.UI.createLabel({
        left:    10,
        width:   Ti.UI.FILL,
        height:  Ti.UI.FILL,
        text:    text,
        color:   '#fff',
        font:    { fontFamily: 'Helvetica Neue', fontSize: 16, fontWeight: 'bold' }
    });

    view.add(activityIndicator);
    view.add(label);
    win.add(view);

    function openIndicator() {
        win.open();
        activityIndicator.show();
    }

    win.openIndicator = openIndicator;

    function closeIndicator() {
        activityIndicator.hide();
        win.close();
    }

    win.closeIndicator = closeIndicator;

    return win;
}

// Public interface
exports.createIndicatorWindow = createIndicatorWindow

像这样在你的代码中使用

var uie = require('lib/indicator');
var indicator = uie.createIndicatorWindow();

someViewObject.addEventListener('click', function(e) {
    indicator.openIndicator();

    setTimeout(function() {
        // Do the work that takes a while
        // and requires an activity indicator
        indicator.closeIndicator();
    },0);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多