Im a noob để phát triển android và tôi gặp sự cố khi vô hiệu hóa chế độ xem. Tôi đang sử dụng hướng dẫn this và không có vấn đề gì khi triển khai. Tuy nhiên, khi tôi thay đổi nền của khung nhìn, nó vẫn phản ứng như thể nền trước đó vẫn được thiết lập. Nói cách khác, tôi thay đổi mặt nạ nhưng lớp "touchview" của tôi không nhìn thấy mặt nạ mới. Tôi đã không có may mắn bằng cách sử dụng không hợp lệ để cập nhật chế độ xem và tôi đã xác minh rằng mặt nạ thực sự được đặt lại làm nền. Mọi sự trợ giúp sẽ rất được trân trọng.Tại sao Chế độ xem tùy chỉnh không làm mất hiệu lực?
MY MÃ
@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;
}
Tại sao bạn không sử dụng R.id.itemId trong trường hợp câu lệnh, Nó đơn giản hơn. Bạn có thực sự chắc chắn mã của bạn được gọi không? và liên kết bị hỏng, vui lòng đăng mã của bạn tại đây. – VinceStyling
Action Bar Sherlock làm cho tôi tạo các mục menu với id int. Liên kết ở trên các công trình và mã được gọi. –