1

我有一个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);

}
4

1 回答 1

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 出现时立即进行图像动画

于 2014-01-12T08:10:08.640 回答