Skip to content

Instantly share code, notes, and snippets.

@ryugoo
Created March 28, 2013 02:46
Show Gist options
  • Select an option

  • Save ryugoo/5260124 to your computer and use it in GitHub Desktop.

Select an option

Save ryugoo/5260124 to your computer and use it in GitHub Desktop.
Titanium Mobile ScrollableView minimal apps sample.
/*jslint devel:true */
/*global Titanium */
(function (Ti) {
"use strict";
var tabGroup, tab, win, sview;
tabGroup = Ti.UI.createTabGroup();
win = Ti.UI.createWindow({
backgroundColor: "#FFFFFF",
title: "Photo Gallery",
tabBarHidden: true
});
tab = Ti.UI.createTab({
window: win
});
sview = Ti.UI.createScrollView({
contentWidth: Ti.Platform.displayCaps.platformWidth,
contentHeight: "auto",
width: Ti.UI.FILL,
height: Ti.UI.FILL,
showVerticalScrollIndicator: true,
showHorizontalScrollIndicator: true,
layout: "horizontal"
});
win.add(sview);
// アプリを開いたら行う処理
tab.addEventListener("focus", function () {
var http;
http = Ti.Network.createHTTPClient();
http.open("get", "http://imthinker.net/sample.json?rnd=" + Date.now());
http.onload = function () {
var thums = [],
views = [],
scWin,
scView,
data = (JSON.parse(http.responseText)).data,
i,
l;
scWin = Ti.UI.createWindow({
backgroundColor: "#FFFFFF"
});
thums = data.map(function (item) {
var imgView;
imgView = Ti.UI.createImageView({
hires: true,
image: item.img,
width: 57,
height: 57,
top: 6,
left: 6,
backgroundColor: "#000000",
imgId: item.id
});
imgView.addEventListener("click", function () {
scView.currentPage = imgView.imgId - 1;
tab.open(scWin);
});
sview.add(imgView);
return imgView;
});
views = data.map(function (item) {
var view, imgView;
view = Ti.UI.createView({
backgroundColor: "#FFFFFF",
width: Ti.UI.FILL,
height: Ti.UI.FILL
});
imgView = Ti.UI.createImageView({
hires: true,
image: item.img,
width: 57,
height: 57
});
view.add(imgView);
return view;
});
scView = Ti.UI.createScrollableView({
views: views,
backgroundColor: "#FFFFFF"
});
scWin.add(scView);
};
http.onerror = function (err) {
alert("HTTPClient でエラーが発生しました。詳細はコンソールログを見てください。");
console.log("-- Start httpclient log -------------------------------------------------------");
console.log(JSON.stringify({
status: http.status,
error: err
}));
console.log("-- End httpclient log ---------------------------------------------------------");
};
http.send(null);
});
tabGroup.addTab(tab);
tabGroup.open();
}(Titanium));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment