7
我是一個noob android開發,我有問題使視圖無效。我正在使用this教程,並沒有實現它的問題。但是,當我更改視圖的背景時,它仍然會響應,就好像前一個背景仍然設置一樣。換句話說,我改變了面具,但我的「touchview」類沒有看到新的面具。我沒有運氣使用invalidate更新視圖,我已經驗證了mask實際上被重置爲背景。任何幫助將不勝感激。爲什麼自定義視圖不會失效?
我的代碼
@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;
}
爲什麼不在case case語句中使用R.id.itemId,這更直接。你真的確定你的代碼被調用嗎?並且鏈接已損壞,請在此處發佈您的代碼。 – VinceStyling 2013-05-13 02:14:43
Action Bar Sherlock讓我用int id創建菜單項。上面的鏈接工作和代碼被調用。 – 2013-05-13 18:27:32