Titanium 将listview项水平滑动到显示按钮
我有一个listView控件,现在在每次滑动listView项时,我想显示另一个带有按钮的视图,我如何在IOS和Android上实现这一点Titanium 将listview项水平滑动到显示按钮,titanium,titanium-alloy,appcelerator-alloy,Titanium,Titanium Alloy,Appcelerator Alloy,我有一个listView控件,现在在每次滑动listView项时,我想显示另一个带有按钮的视图,我如何在IOS和Android上实现这一点 <Alloy> <Window id="index"> <ListView id="list" defaultItemTemplate='template' > <Templates> <ItemTemplate name="template" id="te
<Alloy>
<Window id="index">
<ListView id="list" defaultItemTemplate='template' >
<Templates>
<ItemTemplate name="template" id="template" >
<View layout="horizontal" onSwipe="leftViewSwipe">
<View backgroundColor="red" height="Titanium.UI.FILL" bindId="leftView" width="Titanium.UI.FILL" ></View>
<View backgroundColor="blue" height="Titanium.UI.FILL" bindId="rightView" width="Titanium.UI.FILL" ></View>
</View>
</ItemTemplate>
</Templates>
<ListSection/>
</ListView>
</Window>
看一看。有了这个代码库,您可以实现所需的功能
另一种方法是使用ListView并收听滑动事件。查看。有了这个代码库,您可以实现所需的功能
另一种方法是使用ListView并收听滑动事件。尝试此commonJS模块并根据您的需求进行自定义,您还可以根据自己的使用情况简化它。该系统可在iOS和Android上运行,但以下示例适用于iOS(由于NavWindow) app.js:
var win = Ti.UI.createWindow({backgroundColor:'white', title:'SWIPEABLE CELL'})
var navWin = Ti.UI.iOS.createNavigationWindow({
window:win
})
function genWindow(module) {
var ListTest = require(module);
var win = new ListTest();
return win;
}
var b1 = Ti.UI.createButton({title:'LIST VIEW SAMPLE', bottom:100});
win.add(b1);
b1.addEventListener('click',function(e){
navWin.openWindow(genWindow('listviewsample'));
});
navWin.open();
listviewsample.js:
function leftSwipeHandler(e) {
if (e.direction == 'left') {
var theItem = e.section.getItemAt(e.itemIndex);
theItem.template = 't2';
e.section.updateItemAt(e.itemIndex,theItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.LEFT});
}
}
function rightSwipeHandler(e) {
if (e.direction == 'right') {
var theItem = e.section.getItemAt(e.itemIndex);
theItem.template = 't1';
e.section.updateItemAt(e.itemIndex,theItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.RIGHT});
}
}
function trashHandler(e) {
e.section.deleteItemsAt(e.itemIndex,1,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
function doneHandler(e) {
var theItem = e.section.getItemAt(e.itemIndex);
theItem.template = 't3';
e.section.updateItemAt(e.itemIndex,theItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
var baseTemplate = {
properties:{height:50},
childTemplates: [
{
type: 'Ti.UI.View',
events:{
swipe:leftSwipeHandler
},
childTemplates:[
{
type:'Ti.UI.Label',
bindId:'content',
properties:{left:10,touchEnabled:false,color:'black'}
}
]
}
]
};
var controlTemplate = {
properties:{height:50},
childTemplates: [
{
type: 'Ti.UI.View',
properties:{left:-150,width:'100%'},
events:{
swipe:rightSwipeHandler
},
childTemplates:[
{
type:'Ti.UI.Label',
bindId:'content',
properties:{left:10,touchEnabled:false,color:'black'}
}
]
},
{
type:'Ti.UI.Label',
properties:{color:'white',text:'Trash',width:75,right:75, height:50, backgroundColor:'red', textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER},
events:{
click:trashHandler
}
},
{
type:'Ti.UI.Label',
properties:{color:'white',text:'Finish',width:75,right:0, height:50, backgroundColor:'green', textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER},
events:{
click:doneHandler
}
}
]
}
var doneTemplate = {
properties:{height:50},
childTemplates: [
{
type: 'Ti.UI.View',
childTemplates:[
{
type:'Ti.UI.Label',
bindId:'content',
properties:{left:10,touchEnabled:false, color:'green'}
}
]
}
]
};
var data = [];
for(var i=0;i<20;i++) {
data.push({properties:{backgroundColor:'white',selectionStyle:Ti.UI.iPhone.ListViewCellSelectionStyle.NONE},content:{text:'THIS IS A TASK INDEX'+(i+1)}})
}
var section = Ti.UI.createListSection({items:data});
var listView = Ti.UI.createListView({
sections:[section],
templates:{'t1':baseTemplate,'t2':controlTemplate,'t3':doneTemplate},
defaultItemTemplate:'t1'
})
function listviewsample() {
var win = Ti.UI.createWindow({backgroundColor:'white', title:'LISTVIEW', backButtonTitle:'BACK'});
win.add(listView);
return win;
}
module.exports = listviewsample;
函数leftSwipeHandler(e){
如果(e.方向==‘左’){
var-Iteem=e.section.getItemAt(e.itemIndex);
item.template='t2';
e、 updateItemMat(e.itemIndex,itItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.LEFT});
}
}
函数rightSwipeHandler(e){
如果(e.方向=‘右’){
var-Iteem=e.section.getItemAt(e.itemIndex);
item.template='t1';
e、 updateItemMat(e.itemIndex,itItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.RIGHT});
}
}
函数垃圾处理程序(e){
e、 deleteItemsAt(e.itemIndex,1,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
函数doneHandler(e){
var-Iteem=e.section.getItemAt(e.itemIndex);
item.template='t3';
e、 updateItemMat(e.itemIndex,itItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
var baseTemplate={
属性:{高度:50},
子模板:[
{
键入:“Ti.UI.View”,
活动:{
滑动:左滑动处理程序
},
子模板:[
{
类型:'Ti.UI.Label',
bindId:“内容”,
属性:{left:10,touchEnabled:false,颜色:'black'}
}
]
}
]
};
变量控制模板={
属性:{高度:50},
子模板:[
{
键入:“Ti.UI.View”,
属性:{左:-150,宽度:'100%},
活动:{
滑动:右滑动处理程序
},
子模板:[
{
类型:'Ti.UI.Label',
bindId:“内容”,
属性:{left:10,touchEnabled:false,颜色:'black'}
}
]
},
{
类型:'Ti.UI.Label',
属性:{color:'white',text:'Trash',width:75,right:75,height:50,backgroundColor:'red',textAlign:Ti.UI.text\u ALIGNMENT\u CENTER},
活动:{
单击:垃圾处理程序
}
},
{
类型:'Ti.UI.Label',
属性:{color:'white',text:'Finish',width:75,right:0,height:50,backgroundColor:'green',textAlign:Ti.UI.text\u ALIGNMENT\u CENTER},
活动:{
单击:doneHandler
}
}
]
}
变量doneTemplate={
属性:{高度:50},
子模板:[
{
键入:“Ti.UI.View”,
子模板:[
{
类型:'Ti.UI.Label',
bindId:“内容”,
属性:{left:10,touchEnabled:false,颜色:'green'}
}
]
}
]
};
var数据=[];
对于(var i=0;i请尝试此commonJS模块并根据您的心愿进行自定义,您也可以根据自己的使用情况对其进行简化。此系统在iOS和Android上工作,尽管以下示例适用于iOS(由于NavWindow)
app.js:
var win = Ti.UI.createWindow({backgroundColor:'white', title:'SWIPEABLE CELL'})
var navWin = Ti.UI.iOS.createNavigationWindow({
window:win
})
function genWindow(module) {
var ListTest = require(module);
var win = new ListTest();
return win;
}
var b1 = Ti.UI.createButton({title:'LIST VIEW SAMPLE', bottom:100});
win.add(b1);
b1.addEventListener('click',function(e){
navWin.openWindow(genWindow('listviewsample'));
});
navWin.open();
listviewsample.js:
function leftSwipeHandler(e) {
if (e.direction == 'left') {
var theItem = e.section.getItemAt(e.itemIndex);
theItem.template = 't2';
e.section.updateItemAt(e.itemIndex,theItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.LEFT});
}
}
function rightSwipeHandler(e) {
if (e.direction == 'right') {
var theItem = e.section.getItemAt(e.itemIndex);
theItem.template = 't1';
e.section.updateItemAt(e.itemIndex,theItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.RIGHT});
}
}
function trashHandler(e) {
e.section.deleteItemsAt(e.itemIndex,1,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
function doneHandler(e) {
var theItem = e.section.getItemAt(e.itemIndex);
theItem.template = 't3';
e.section.updateItemAt(e.itemIndex,theItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
var baseTemplate = {
properties:{height:50},
childTemplates: [
{
type: 'Ti.UI.View',
events:{
swipe:leftSwipeHandler
},
childTemplates:[
{
type:'Ti.UI.Label',
bindId:'content',
properties:{left:10,touchEnabled:false,color:'black'}
}
]
}
]
};
var controlTemplate = {
properties:{height:50},
childTemplates: [
{
type: 'Ti.UI.View',
properties:{left:-150,width:'100%'},
events:{
swipe:rightSwipeHandler
},
childTemplates:[
{
type:'Ti.UI.Label',
bindId:'content',
properties:{left:10,touchEnabled:false,color:'black'}
}
]
},
{
type:'Ti.UI.Label',
properties:{color:'white',text:'Trash',width:75,right:75, height:50, backgroundColor:'red', textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER},
events:{
click:trashHandler
}
},
{
type:'Ti.UI.Label',
properties:{color:'white',text:'Finish',width:75,right:0, height:50, backgroundColor:'green', textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER},
events:{
click:doneHandler
}
}
]
}
var doneTemplate = {
properties:{height:50},
childTemplates: [
{
type: 'Ti.UI.View',
childTemplates:[
{
type:'Ti.UI.Label',
bindId:'content',
properties:{left:10,touchEnabled:false, color:'green'}
}
]
}
]
};
var data = [];
for(var i=0;i<20;i++) {
data.push({properties:{backgroundColor:'white',selectionStyle:Ti.UI.iPhone.ListViewCellSelectionStyle.NONE},content:{text:'THIS IS A TASK INDEX'+(i+1)}})
}
var section = Ti.UI.createListSection({items:data});
var listView = Ti.UI.createListView({
sections:[section],
templates:{'t1':baseTemplate,'t2':controlTemplate,'t3':doneTemplate},
defaultItemTemplate:'t1'
})
function listviewsample() {
var win = Ti.UI.createWindow({backgroundColor:'white', title:'LISTVIEW', backButtonTitle:'BACK'});
win.add(listView);
return win;
}
module.exports = listviewsample;
函数leftSwipeHandler(e){
如果(e.方向==‘左’){
var-Iteem=e.section.getItemAt(e.itemIndex);
item.template='t2';
e、 updateItemMat(e.itemIndex,itItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.LEFT});
}
}
函数rightSwipeHandler(e){
如果(e.方向=‘右’){
var-Iteem=e.section.getItemAt(e.itemIndex);
item.template='t1';
e、 updateItemMat(e.itemIndex,itItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.RIGHT});
}
}
函数垃圾处理程序(e){
e、 deleteItemsAt(e.itemIndex,1,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
函数doneHandler(e){
var-Iteem=e.section.getItemAt(e.itemIndex);
item.template='t3';
e、 updateItemMat(e.itemIndex,itItem,{animated:true,animationStyle:Titanium.UI.iPhone.RowAnimationStyle.FADE});
}
var baseTemplate={
属性:{高度:50},
子模板:[
{
键入:“Ti.UI.View”,
活动:{
滑动:左滑动处理程序
},
子模板:[
{
类型:'Ti.UI.Label',
bindId:“内容”,
属性:{left:10,touchEnabled:false,颜色:'black'}
}
]
}
]
};
变量控制模板={
属性:{高度:50},
子模板:[
{
键入:“Ti.UI.View”,
属性:{左:-150,宽度:'100%},
活动:{
滑动:右滑动处理程序