Appcelerator ImageView,更改android上的图像闪烁/闪烁
我有20张图片,我在上面循环展示了一个健身运动。更新图像时(即从第1帧到第2帧),整个imageView闪烁。这只发生在安卓系统上,在iOS系统上运行良好 这里有一段视频 这是在emulator上进行的,但在我测试过的所有android设备上也会发生 我尝试将imageView更改为只包含背景图像的视图,这可以不闪烁地工作,但是运行速度非常慢,占用了大量内存,并且经常崩溃Appcelerator ImageView,更改android上的图像闪烁/闪烁,android,imageview,appcelerator,flicker,appcelerator-titanium,Android,Imageview,Appcelerator,Flicker,Appcelerator Titanium,我有20张图片,我在上面循环展示了一个健身运动。更新图像时(即从第1帧到第2帧),整个imageView闪烁。这只发生在安卓系统上,在iOS系统上运行良好 这里有一段视频 这是在emulator上进行的,但在我测试过的所有android设备上也会发生 我尝试将imageView更改为只包含背景图像的视图,这可以不闪烁地工作,但是运行速度非常慢,占用了大量内存,并且经常崩溃 exports.imagesWindow = function(exercise, noOfImages) { va
exports.imagesWindow = function(exercise, noOfImages) {
var win = new SS.ui.win('landscape');
var imgCount = 0;
var header = new SS.ui.view(win, '10%', '100%'); header.top = 0; header.visible = true; header.backgroundColor = SS.ui.colors[0];
var cueText = new SS.ui.normalLabel(header, "some text", 7); cueText.color = 'white';
//var imgLeft = new SS.ui.responsiveImage({container:win, top:'10%', left:'2%', height: '75%', width: '30%', zoom: 0.3});
//var imgCenter = new SS.ui.responsiveImage({container:win, top: '10%', left: '35%', height: '75%', width: '30%', zoom: 0.3});
//var imgRight = new SS.ui.responsiveImage({container:win, top:'10%', left: '68%', height:'75%', width:'30%', zoom: 0.3});
if (noOfImages === 3) {
imgLeft = new ImagePanel(win, '17%');
imgCenter = new ImagePanel(win, '50%');
imgRight = new ImagePanel(win, '83%');
}
else {
imgLeft = new ImagePanel(win, '30%');
imgRight = new ImagePanel(win, '70%');
}
function updateImages() {
cueText.text = (eval(exercise + "Cues"))[imgCount];
instructionNumber.text = (imgCount+1) + "/20";
if (noOfImages === 3) {
imgLeft.image = '/images/instructionImages/' + exercise + "/" + exercise + '_front_' + imgCount + '.jpg';
imgCenter.image = '/images/instructionImages/' + exercise + "/" + exercise + '_side_' + imgCount + '.jpg';
imgRight.image = '/images/instructionImages/' + exercise + "/" + exercise + '_back_' + imgCount + '.jpg';
//SS.log("image updated: " + imgLeft.image + " " + imgCenter.image + " " + imgRight.image);
}
else {
imgLeft.image = '/images/instructionImages/' + exercise + "/" + exercise + '_front_' + imgCount + '.jpg';
imgRight.image = '/images/instructionImages/' + exercise + "/" + exercise + '_side_' + imgCount + '.jpg';
}
}
//view.add(win);
var homeView = new SS.ui.view(win, '12%', '30%'); homeView.center = {x: '5%', y: '92%'}; homeView.visible = true;
var home = new SS.ui.dateButton(homeView, 'footer/home');
home.addEventListener('click', function(){ if (start){ clearInterval(start); }; win.close(); });
var footerView = new SS.ui.view(win, '12%', '30%'); footerView.center = {x: '50%', y: '92%'}; footerView.visible = true;
var prevImg = new SS.ui.dateButton(footerView, 'footer/prevFrame'); prevImg.left = 0;
//prevImg.height = Ti.UI.SIZE;prevImg.width = Ti.UI.SIZE;
prevImg.addEventListener('click', goToPrev);
var nextImg = new SS.ui.dateButton(footerView, 'footer/nextFrame'); //nextImg.height = Ti.UI.SIZE; nextImg.width = Ti.UI.SIZE;
nextImg.addEventListener('click', goToNext); nextImg.right = 0;
var stopPlayBtn = new SS.ui.dateButton(footerView, 'footer/playVideo'); //stopPlayBtn.height = Ti.UI.SIZE;stopPlayBtn.width = Ti.UI.SIZE;
stopPlayBtn.addEventListener('click', stopPlay);
var numberView = new SS.ui.view(win, '12%', '30%'); numberView.center = {x: '95%', y: '92%'}; numberView.visible = true;
var instructionNumber = new SS.ui.normalLabel(numberView, (imgCount+1) + "/20", 5);
updateImages();
var start;
function stopPlay() {
// start videos
if (stopPlayBtn.image.indexOf('play')>=0) { cueText.visible = false; start = setInterval(goToNext, 200); stopPlayBtn.image = '/images/footer/stopVideo.png';}
// stop vidoes
else { clearInterval(start); cueText.visible = true; stopPlayBtn.image = '/images/footer/playVideo.png'; }
}
function goToPrev() {
if (imgCount > 0) { imgCount--; }
else { imgCount = 19; };
SS.log("imgCount: " + imgCount);
updateImages();
}
function goToNext() {
if (imgCount < 19) { imgCount++; }
else { imgCount = 0; };
SS.log("imgCount: " + imgCount);
updateImages();
}
return win;
};
var ImagePanel = function(viewToAdd, cX) {
var imageView = Ti.UI.createImageView({
width: '30%',
borderColor: 'white',
center: {x: cX, y: '50%'}
});
viewToAdd.add(imageView);
//resize for tablets
if(Ti.Platform.osname.indexOf('ipad') >=0) {
imageView.height = '45%';
imageView.borderWidth = 8;
imageView.borderRadius = 12;
}
else {
imageView.height = '65%';
imageView.borderWidth = 4;
imageView.borderRadius = 6;
}
return imageView;
};
exports.imagesWindow=函数(练习,noOfImages){
var-win=新的SS.ui.win('scape');
var imgCount=0;
var header=new SS.ui.view(win,'10%,'100%);header.top=0;header.visible=true;header.backgroundColor=SS.ui.colors[0];
var cueText=new SS.ui.normalLabel(标题,“一些文本”,7);cueText.color='white';
//var imgLeft=new SS.ui.responsiveImage({容器:win,顶部:'10%,左侧:'2%,高度:'75%,宽度:'30%,缩放:0.3});
//var imgCenter=new SS.ui.responsiveImage({container:win,top:10%,left:35%,height:75%,width:30%,zoom:0.3});
//var imgRight=new SS.ui.responsiveImage({容器:win,顶部:'10%,左侧:'68%,高度:'75%,宽度:'30%,缩放:0.3});
如果(noOfImages==3){
imgLeft=新的ImagePanel(赢,'17%');
imgCenter=新的图像面板(赢得“50%”);
imgRight=新的ImagePanel(赢得“83%”);
}
否则{
imgLeft=新的ImagePanel(赢得“30%”);
imgRight=新的ImagePanel(赢得“70%”);
}
函数updateImages(){
cueText.text=(评估(练习+“提示”)[imgCount];
指令number.text=(imgCount+1)+“/20”;
如果(noOfImages==3){
imgLeft.image='/images/instructionImages/'+exercise+“/”+exercise+''u front'+imgCount+'.jpg';
imgCenter.image='/images/instructionImages/'+exercise+“/”+exercise+''u-side'+imgCount+'.jpg';
imgRight.image='/images/instructionImages/'+exercise+“/”+exercise+''u back'+imgCount+'.jpg';
//SS.log(“图像更新:“+imgLeft.image+”“+imgCenter.image+”“+imgRight.image”);
}
否则{
imgLeft.image='/images/instructionImages/'+exercise+“/”+exercise+''u front'+imgCount+'.jpg';
imgRight.image='/images/instructionImages/'+exercise+“/”+exercise+''u-side'+imgCount+'.jpg';
}
}
//查看。添加(win);
var homeView=new SS.ui.view(win,'12%,'30%);homeView.center={x:'5%',y:'92%};homeView.visible=true;
var home=newss.ui.dateButton(homeView,'footer/home');
addEventListener('click',function(){if(start){clearInterval(start);};win.close();});
var footerView=new SS.ui.view(win,'12%,'30%);footerView.center={x:'50%',y:'92%};footerView.visible=true;
var prevImg=new SS.ui.dateButton(footerView,'footer/prevFrame');prevImg.left=0;
//prevImg.height=Ti.UI.SIZE;prevImg.width=Ti.UI.SIZE;
上一个addEventListener('click',goToPrev');
var nextImg=new SS.ui.dateButton(footerView,'footer/nextFrame');//nextImg.height=Ti.ui.SIZE;nextImg.width=Ti.ui.SIZE;
nextImg.addEventListener('click',goToNext);nextImg.right=0;
var stopPlayBtn=new SS.ui.dateButton(footerView,'footer/playVideo');//stopPlayBtn.height=Ti.ui.SIZE;stopPlayBtn.width=Ti.ui.SIZE;
stopPlayBtn.addEventListener('click',stopPlay');
var numberView=new SS.ui.view(win,'12%,'30%);numberView.center={x:'95%',y:'92%};numberView.visible=true;
var指令编号=新SS.ui.normalLabel(numberView,(imgCount+1)+“/20”,5);
更新图像();
var启动;
函数stopPlay(){
//启动视频
如果(stopPlayBtn.image.indexOf('play')>=0){cueText.visible=false;start=setInterval(goToNext,200);stopPlayBtn.image='/images/footer/stopVideo.png';}
//阻止维多斯
else{clearInterval(start);cueText.visible=true;stopPlayBtn.image='/images/footer/playVideo.png';}
}
函数goToPrev(){
如果(imgCount>0){imgCount--;}
else{imgCount=19;};
SS.log(“imgCount:+imgCount”);
更新图像();
}
函数goToNext(){
if(imgCount<19){imgCount++;}
else{imgCount=0;};
SS.log(“imgCount:+imgCount”);
更新图像();
}
回归胜利;
};
var ImagePanel=函数(viewToAdd,cX){
var imageView=Ti.UI.createImageView({
宽度:“30%”,
边框颜色:“白色”,
中心:{x:cX,y:'50%'}
});
viewToAdd.add(图像视图);
//调整平板电脑的大小
如果(Ti.Platform.osname.indexOf('ipad')>=0){
imageView.height='45%';
imageView.borderWidth=8;
imageView.borderRadius=12;
}
否则{
imageView.height='65%';
imageView.borderWidth=4;
imageView.borderRadius=6;
}
返回图像视图;
};
编辑
因此,在进一步挖掘之后,我发现了这篇文章-
在android上,图像大小似乎是一个限制因素,减小图像大小有助于解决这一问题,尽管它在第一个图像周期中仍会闪烁。在imageview周围添加一个视图(容器视图),并执行以下操作:
- 将另一个具有新图像的视图添加到容器视图中
- 加载图像后,从容器视图中删除级别为0的imageview
- 将另一个具有新图像的视图添加到容器视图中
- 加载图像后,删除级别为0的imageview
<View id="container"></View>
// first image var img = Ti.UI.createImageView(); $.container.add(img); function changeImage(){ // changing images and remove the old one var img = Ti.UI.createImageView(); $.container.add(img); $.container.remove($.container.getChildren()[0]); // or fade out }