我是 android 开发的菜鸟,我在使视图无效时遇到问题。我正在使用本教程,实施它没有问题。但是,当我更改视图的背景时,它仍然会响应,就好像仍然设置了以前的背景一样。换句话说,我更改了掩码,但我的“touchview”类没有看到新掩码。我没有运气使用 invalidate 来更新视图,并且我已经验证了掩码实际上被重置为背景。任何帮助将不胜感激。
我的代码
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId())
{
case 1: // id from the xml file
if(isMale){
isMale=false;
item.setIcon(R.drawable.male_icon);
imageViewOriginal.setImageResource(R.drawable.woman_front);
imageViewFlip.setImageResource(R.drawable.woman_back);
if(isFrontView){
myMask.setBackgroundResource(R.drawable.woman_front_mask); //Mask changed here
}else{
myMask.setBackgroundResource(R.drawable.woman_back_mask); //Mask changed here
}
}else{
isMale=true;
item.setIcon(R.drawable.female_icon);
imageViewOriginal.setImageResource(R.drawable.man_front);
imageViewFlip.setImageResource(R.drawable.man_back);
if(isFrontView){
myMask.setBackgroundResource(R.drawable.man_front_mask); //Mask changed here
}else{
myMask.setBackgroundResource(R.drawable.man_back_mask); //Mask changed here
}
}
touchView.invalidate();
infoView.invalidate();
myMask.invalidate(); //Mask View Invalidated here
return true; // we handled the click, dont pass it up the chain
case 2: // id from the xml file
if(isFrontView){
isFrontView=false;
if(isMale){
myMask.setBackgroundResource(R.drawable.man_back_mask); //Mask changed here
}else{
myMask.setBackgroundResource(R.drawable.woman_back_mask); //Mask changed here
}
}else{
isFrontView=true;
if(isMale){
myMask.setBackgroundResource(R.drawable.man_front_mask); //Mask changed here
}else{
myMask.setBackgroundResource(R.drawable.woman_front_mask); //Mask changed here
}
}
FlipAnimator animator = new FlipAnimator(imageViewOriginal, imageViewFlip,
imageViewFlip.getWidth() / 2, imageViewFlip.getHeight() / 2);
if (imageViewOriginal.getVisibility() == View.GONE) {
animator.reverse();
}
flipLayout.startAnimation(animator);
touchView.invalidate();
infoView.invalidate();
myMask.invalidate(); //Mask View Invalidated here
return true;
}
return false;
}