0

我在 appcelerator 工作,我有一个选项卡,它是个人资料。上半部分是头像、姓名和其他杂项,下半部分是推特时间线。当我开始添加 twitter 时间线代码时,它占据了整个屏幕。有没有办法减少时间线,只占用屏幕的一部分才能看到其他项目?

这是我的推特时间线代码:

var twitterUserName = "foundationsix";
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/" + 
"user_timeline.json?count=10&screen_name=" + twitterUserName);

var twitterData = [];
httpClient.onload = function() {
try {


    var tweets = JSON.parse(this.responseText);
    for (var i=0; i < tweets.length; i++) {

        var tweetText = tweets[i].text;
        var user = tweets[i].user.screen_name;
        var avatar = tweets[i].user.profile_image_url;
        var created_at = tweets[i].created_at;

        var row = Ti.UI.createTableViewRow({hasChild:true,
            height:'auto'});

            var postView = Ti.UI.createView({
            height:'55',
            top:5,
            bottom:5,
            left:5,
            right:5,

        });

        var avatarImageView = Ti.UI.createImageView({
            image:avatar,
            left:0,
            top:0,
            height:48,
            width:48
        });

        postView.add(avatarImageView);

        var userLabel = Ti.UI.createLabel({
            text:user,
            left:54,
            width:120,
            top:-48,
            bottom:2,
            height:16,
            textAlign:'left',
            color:'#444444',
            font:{fontFamily:'Trebuchet MS',fontSize:14,
                fontWeight:'bold'}
        });

        postView.add(userLabel);

        var dateLabel = Ti.UI.createLabel({
            text:created_at,
            right:0,
            top:-18,
            bottom:2,
            height:14,
            textAlign:'right',
            width:110,
            color:'#444444',
            font:{fontFamily:'Trebuchet MS',fontSize:12}
        });

        postView.add(dateLabel);

        var tweetTextLabel = Ti.UI.createLabel({
            text:tweetText,
            left:54,
            top:0,
            bottom:2,
            height:'auto',
            width:236,
            textAlign:'left',
            font:{fontSize:14}
        });

        postView.add(tweetTextLabel);
        row.add(postView);
        twitterData[i] = row;
    }


    var tableview = Titanium.UI.createTableView({data:twitterData,
        minRowHeight:58});
    win1.add(tableview);

} 
catch(E) {
    alert(E);
}
 };
          httpClient.send();
4

1 回答 1

0

请记住..我们需要使用顶部和左侧或底部和右侧..不要在同一元素中混合顶部和底部....

来解决你的问题..把顶部放到桌子上,让它下来.......

我创建了顶视图,您可以在其中指定用户名等

您可以在下面发布时间表

var win1=Ti.UI.createWindow()


///// this is top portion 
var topView=Ti.UI.createView({
    top:0,
    left:0,
    height:100,
    background:"#2d2d2d"
})

var username=Ti.UI.createLabel({
    text:"foundationsix",
    color:"#fff"
})

topView.add(username)
 win1.add(topView)





var twitterUserName = "foundationsix";
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/" + "user_timeline.json?count=10&screen_name=" + twitterUserName);

var twitterData = [];
httpClient.onload = function() {
try {


    var tweets = JSON.parse(this.responseText);
    for (var i=0; i < tweets.length; i++) {

        var tweetText = tweets[i].text;
        var user = tweets[i].user.screen_name;
        var avatar = tweets[i].user.profile_image_url;
        var created_at = tweets[i].created_at;

        var row = Ti.UI.createTableViewRow({hasChild:true,
            height:'auto'});

            var postView = Ti.UI.createView({height:55});

        var avatarImageView = Ti.UI.createImageView({
            image:avatar,
            left:0,
            top:0,
            height:48,
            width:48
        });

        postView.add(avatarImageView);

        var userLabel = Ti.UI.createLabel({
            text:user,
            left:54,
            width:120,
            top:-48,
            bottom:2,
            height:16,
            textAlign:'left',
            color:'#444444',
            font:{fontFamily:'Trebuchet MS',fontSize:14,
                fontWeight:'bold'}
        });

        postView.add(userLabel);

        var dateLabel = Ti.UI.createLabel({
            text:created_at,
            right:0,
            top:-18,
            bottom:2,
            height:14,
            textAlign:'right',
            width:110,
            color:'#444444',
            font:{fontFamily:'Trebuchet MS',fontSize:12}
        });

        postView.add(dateLabel);

        var tweetTextLabel = Ti.UI.createLabel({
            text:tweetText,
            left:54,
            top:0,
            bottom:2,
            height:'auto',
            width:236,
            textAlign:'left',
            font:{fontSize:14}
        });

        postView.add(tweetTextLabel);
        row.add(postView);
        twitterData[i] = row;
    }


    var tableview = Titanium.UI.createTableView({
        data:twitterData,
        minRowHeight:58,
        top:100
        });
    win1.add(tableview);

} 
catch(E) {
    alert(E);
}
 };
          httpClient.send();


win1.open()
于 2013-02-28T05:08:05.847 回答