2013-03-17 50 views
1

我有一个ImageView。我想为点击它的单个图像创建动画。 但是,当滚动我看到两个图像动画。为什么?当滚动动画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); 

} 

回答

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()中,以便活动出现者立即生成图像动画