1

我想使用 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;

提前致谢。

4

1 回答 1

2

只需创建文件 (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);
});
于 2013-04-11T05:31:48.890 回答