1

我希望我的 ImageView 首先从屏幕的中心到左侧的屏幕外,然后我希望它从右侧的屏幕外移动到屏幕的中心。

但它只是从屏幕右侧进入中心,然后暂停,然后转到屏幕左侧。不管我怎么做,它都会这样做。这是代码:

public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    Display display = getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth(); 

    final AnimationSet anmSet;

    anmSet = new AnimationSet(hasFocus);
    imgCenter = (ImageView)findViewById(R.id.imgCenter);
    btnGoLeft = (ImageButton)findViewById(R.id.btnGoLeft);
    imgCenter.setImageDrawable(list.get(0).getImage());
    TranslateAnimation moveBack = new TranslateAnimation(0,-500, 0, 0);
    moveBack.setDuration(500);
    moveBack.setStartOffset(200);
    anmSet.addAnimation(moveBack);

    TranslateAnimation moveLeft = new TranslateAnimation(width,width/2-imgCenter.getWidth()/2-60, 0, 0); 
    moveLeft.setDuration(500);
    moveLeft.setStartOffset(2000);
    anmSet.addAnimation(moveLeft);

    btnGoLeft.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v) {
            imgCenter.startAnimation(anmSet);
        }
    });  
}
4

0 回答 0