我知道这是非常简单的事情,但我没有看到问题所在。
我有一个线性布局:
LinearLayout menuSlide = (LinearLayout) findViewById(R.id.menuSlide);
menuSlide.startAnimation(new ExpandAnimation(menuSlide, 0, (int) (screenWidth*0.7), 20));
和 ExpandAnimation 类:
public class ExpandAnimation extends Animation implements Animation.AnimationListener{
private View view;
private static int ANIMATION_DURATION;
private static final String LOG_CAT = "ExpandAnimation";
private int lastWidth;
private int fromWidth;
private int toWidth;
private static int STEP_SIZE=30;
public ExpandAnimation(View v,int fromWidth, int toWidth, int duration){
Log.v(LOG_CAT, "Entramos en el constructor del ExpandAnimation");
this.view = v;
ANIMATION_DURATION = 1;
this.fromWidth = fromWidth;
this.toWidth = toWidth;
setDuration(ANIMATION_DURATION);
setRepeatCount(20);
setFillAfter(false);
setInterpolator(new AccelerateInterpolator());
setAnimationListener(this);
startNow();
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.v(LOG_CAT, "Entra en el onAnimationRepeat");
LayoutParams lyp = view.getLayoutParams();
lyp.width = lastWidth += toWidth/20;
view.setLayoutParams(lyp);
Log.v(LOG_CAT,"El objeto: " + view.getId() + " tiene ahora de ancho: " + view.getWidth());
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.v(LOG_CAT, "Entra en el onAnimationStart");
LayoutParams lyp = view.getLayoutParams();
lyp.width = 0;
view.setLayoutParams(lyp);
lastWidth=0;
}
}
好的,程序到达 ExpandAnimation 的构造函数,但没有别的,onAnimationStart 永远不会被触发。
我究竟做错了什么?