2013-03-17 76 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()中,以便活動出現者立即生成圖像動畫