2017-07-05 64 views
0

我正在使用钛扩展和崩溃为Android.I创建了一个标签和图像的表。当我点击图像,然后使底部视图可见性真正和为tablerow设置高度。然后应用动画为展开视图Appcelerator钛动画

for (var i = 0; i < sectionItems.length; i++) { 


       tblCell[i] = Ti.UI.createTableViewRow({ 
        height: 50, 
        backgroundColor: 'white', 
        id: i, 

        layout:"horizontal", 
        rowId:i 
       }); 
      topView[i]=Ti.UI.createView({ 

        height: 50, 
        backgroundColor: 'white', 
        id: i, 
       rowId:i, 
        layout:"horizontal", 
        width:"100%", 

       }); 




       lbltitle[i] = Ti.UI.createLabel({ 
        text: sectionItems[i], 
        id:i, 
        color:'#000', 
        font: { 
         fontSize: '16dp', 
         fontFamily: 'Myriad Pro', 
         fontWeight: 'bold' 
        }, 
       left: "1%", 
       width:'80%', 
       rowId:i, 
        //right: '10', 
        textAlign: Titanium.UI.TEXT_ALIGNMENT_LEFT, 

       }); 
       lblDescription[i] = Ti.UI.createLabel({ 
       // text: sectionItems[i].description, 
        id: i, 
        text:"Test Answer", 
        color:'#000', 
        font: { 
         fontSize: '14dp', 
         fontFamily: 'Myriad Pro', 
        }, 
        backgroundColor:'green', 
        rowId:i, 
        left: "10%", 
        right:"10%", 
        top:"10dp", 
        width:'80%', 
        height:"25%", 
       textAlign: Titanium.UI.TEXT_ALIGNMENT_LEFT, 

       }); 
       addPic[i] = Ti.UI.createImageView({ 
       image:"/images/carat_down.png", 

       rowId:i, 
       id: i, 

       right:"1%", 

       height:'9dp', 
       width:"16dp" 

       }); 
       expandView[i]=Ti.UI.createView({ 
       width:"100%", 
       left:'0dp', 
       height:"0dp", 
       backgroundColor:'red', 
       id: i, 
       rowId:i, 
       visible:false, 
       layout:"vertical" 

       }); 








       topView[i].add(lbltitle[i]); 
       topView[i].add(addPic[i]); 
       expandView[i].add(lblDescription[i]); 
       tblCell[i].add(expandView[i]); 

       tblCell[i].add(topView[i]); 
       addPic[i].addEventListener('singletap', function(e) { 

       toggleExpand(e); 
      }); 

function toggleExpand(e){ 



      if(expandView[e.source.rowId].visible==true){ 

      expandView[e.source.rowId].visible=false; 

       tblCell[e.source.rowId].height=tblCell[e.source.rowId].height-(topView[e.source.rowId].height*3); 
      expandView[e.source.rowId].animate({ 
       height:"0dp",duration:250}); 


      }else{ 
      for (var i = 0; i < tblsectionItems.length; i++) { 
       if(expandView[i].visible==true){ 
        expandView[i].visible=false; 
        tblCell[i].height=tblCell[i].height-(topView[i].height*3); 
        expandView[i].animate({ 
        height:"0dp",duration:250}); 
       }} 

       expandView[e.source.rowId].visible=true; 

       expandView[e.source.rowId].animate({ 
       height:"auto",duration:250});//"auto" 
       tblCell[e.source.rowId].height=tblCell[e.source.rowId].height+(topView[e.source.rowId].height*3); 

      } 
} 

但是,当行然后展开我看不到我以前tblcell.I的元素不能找到reason.Please帮我

回答

0

我认为你需要改变逻辑您正在使用添加行中的元素。 先不使用单独的阵列添加的每个元素,而不是使用行变量附加元素,如下面..

var row = Ti.UI.createTableViewRow({}); 
row.topView = Ti.UI.createView({}); 
row.expandView = Ti.UI.createView({}); like that.. 

然后只使用2个对象为expanView或任何查看您想显示在​​toggleExpand功能/隐藏..像

if(previousView.visible == true) 
{ 
... 
} 
else{ 
... 
} 
previousView = e.row.expandView;