我在RelativeLayout
中有几张图片:
但这就是图像褪色的方式:
fade
完成后,图像恢复正常状态。
我已经被困在这一段时间了,我不知道是什么导致我的图像像这样褪色。我尝试使用clearAnimation()
,但这不起作用。我在android:fillAfter="true"
中添加了xml
但没有结果......
有人可以帮忙吗?
这是我的代码:
*注意 - R.id.rl_images
是图片存储的RelativeLayout
。
**此外,我正在使用Drag and Drop
在屏幕上拖动这些图像。拖动图像后发生fade
错误。如果我需要提供Drag and Drop
方法的代码,请告诉我。我认为问题出在Animation
上,而不是Drag and Drop
。
public void fadeAnimation(View view){
final Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade);
findViewById(R.id.logo1).startAnimation(fadeInAnimation);
findViewById(R.id.logo2).startAnimation(fadeInAnimation);
findViewById(R.id.logo3).startAnimation(fadeInAnimation);
fadeInAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
View view = findViewById(R.id.rl_images);
view.clearAnimation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
编辑为Drag and Drop
听众添加了代码
class MyDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
if(v==findViewById(R.id.buttonId))
findViewById(R.id.removeText).setVisibility(View.VISIBLE);
else
if(v==findViewById(R.id.tBar))
findViewById(R.id.removeText2).setVisibility(View.VISIBLE);
else if(v==findViewById(R.id.rl_images)){
findViewById(R.id.removeText).setVisibility(View.GONE);
findViewById(R.id.removeText2).setVisibility(View.GONE);
}
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
if(v==findViewById(R.id.rl_images)) {
View view = (View) event.getLocalState();
float posx = event.getX();
float posy = event.getY();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
RelativeLayout container = (RelativeLayout) v;
container.addView(view);
view.setX(posx);
view.setY(posy);
view.setVisibility(View.VISIBLE);
findViewById(R.id.removeText).setVisibility(View.GONE);
}else {
findViewById(R.id.removeText).setVisibility(View.GONE);
findViewById(R.id.removeText2).setVisibility(View.GONE);
}break;
case DragEvent.ACTION_DRAG_ENDED:
findViewById(R.id.removeText).setVisibility(View.GONE);
findViewById(R.id.removeText2).setVisibility(View.GONE);
break;
default:
break;
}
return true;
}
}
fade.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:fillAfter="true"
android:duration="2000"/>
</set>