设置动画时出现Android removeview错误 private void kartyafeleanim(字符串idx1,字符串idx2){ Animation anim1=AnimationUtils.loadAnimation(mycontext,R.anim.scalable\u anim); Animation anim2=AnimationUtils.loadAnimation(mycontext,R.anim.scalable\u anim); 试一试{ 对于(inti=0;i
这是android的一个奇怪问题,您不能在animationEnd中更改视图层次结构 你所要做的就是像这样推迟你的电话:设置动画时出现Android removeview错误 private void kartyafeleanim(字符串idx1,字符串idx2){ Animation anim1=AnimationUtils.loadAnimation(mycontext,R.anim.scalable\u anim); Animation anim2=AnimationUtils.loadAnimation(mycontext,R.anim.scalable\u anim); 试一试{ 对于(inti=0;i,android,animation,Android,Animation,这是android的一个奇怪问题,您不能在animationEnd中更改视图层次结构 你所要做的就是像这样推迟你的电话: private void kartyafeleanim(String idx1, String idx2) { Animation anim1=AnimationUtils.loadAnimation(mycontext, R.anim.scalable_anim); Animation anim2=AnimationUtils.loadAnimati
private void kartyafeleanim(String idx1, String idx2) {
Animation anim1=AnimationUtils.loadAnimation(mycontext, R.anim.scalable_anim);
Animation anim2=AnimationUtils.loadAnimation(mycontext, R.anim.scalable_anim);
try {
for (int i=0; i<6; i++) {
LinearLayout LL = (LinearLayout) myLinearLayout.getChildAt(i);
for (int j=0; j<LL.getChildCount(); j++) {
if (LL.getChildAt(j).getTag().toString().equals(idx1) || LL.getChildAt(j).getTag().toString().equals(idx2)) {
final View v = LL.getChildAt(j);
int rtop=0;
if (v.getTag().toString().equals(idx1)) rtop=110+(53*((int)((Integer.parseInt(idx1)-100)/6)));
if (v.getTag().toString().equals(idx2)) rtop=110+(53*((int)((Integer.parseInt(idx2)-100)/6)));
int left=v.getLeft();
int top =v.getTop()+rtop-30;
FrameLayout.LayoutParams lp =new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.LEFT);
lp.setMargins(left, top, 0, 0);
if (v.getTag().toString().equals(idx1)) {
final ImageView img1 =new ImageView(mycontext);
img1.setBackgroundResource(R.drawable.match);
img1.setLayoutParams(lp);
myLinearLayoutAll.addView(img1);
img1.setVisibility(View.VISIBLE);
img1.startAnimation(anim1);
anim1.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
//img1.setVisibility(View.INVISIBLE);
myLinearLayoutAll.removeView(img1);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) { }
});
}
else if (v.getTag().toString().equals(idx2)) {
final ImageView img2 =new ImageView(mycontext);
img2.setBackgroundResource(R.drawable.match);
img2.setLayoutParams(lp);
myLinearLayoutAll.addView(img2);
img2.setVisibility(View.VISIBLE);
img2.startAnimation(anim2);
anim2.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
//img2.setVisibility(View.INVISIBLE);
myLinearLayoutAll.removeView(img2);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) { }
});
}
}
}
}
} catch (Exception ex) {}
}
10-21 08:17:54.605:ERROR/AndroidRuntime(10380):java.lang.NullPointerException+1这是非常有用的信息,它可以工作。您是否有更详细的解释,为什么同样在UI线程中运行的onAnimationEnd不能用于更改视图层次结构,或者至少您是如何找到解决方法的?
@Override
public void onAnimationEnd(Animation animation) {
post(new Runnable() {
public void run() {
myLinearLayoutAll.removeView(img2);
}
});
}