滚动动画ImageView时,会显示两个图像

时间:2013-03-17 19:15:53

标签: android animation android-listview

我有一个ImageView。我想为点击它的单张图片制作动画。 但是当我滚动时,我看到两个动画的图像。为什么呢?

Animation  animationLeft;
ImageAdapter imageAdapter;ListView listView;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
      animationLeft=AnimationUtils.loadAnimation(this, R.anim.transform_left);


     listView=(ListView) findViewById(R.id.listView1);
     imageAdapter=new ImageAdapter(this, items,images);
    listView.setAdapter(imageAdapter);

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int 
      position,
                long arg3) {
            ImageAdapter mAdapter = (ImageAdapter)parent.getAdapter();

            final View vImage=   mAdapter.getView(position, view, 
    parent).findViewById(R.id.imageView1);
             animate(vImage);


        }
    });

}

public void animate(View v){
         TranslateAnimation anim = new TranslateAnimation
(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF,
0.0f);
            anim.setDuration(6000);
             v.startAnimation(anim);

}

1 个答案:

答案 0 :(得分:0)

你的方法public void animate(View v)专注于能够为图像制作动画的视图,因此两个图像是动画的......

尝试在Imageview上单独设置动画,如下所示

public void animate(View v){
ImageView thumbPhoto=(ImageView)view.findViewById(R.id.list_image);
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF,0.0f);
        anim.setDuration(3000);
        thumbPhoto.startAnimation(anim);
}

尝试在可能的情况下调用此方法,可能在onCreate()中,以便在Activity上传后立即生成图像