Android-动态更改自定义列表视图的项目,如幻灯片效果

Android-动态更改自定义列表视图的项目,如幻灯片效果,android,multithreading,listview,slideshow,custom-lists,Android,Multithreading,Listview,Slideshow,Custom Lists,我有一个自定义列表视图,其中使用了四个项目,一个imageview和三个TextView。对于列表中的每个imageview,我有五个图像uri,我想在一定的时间内动态地更改特定imageview项的图像。我应用线程来动态更改图像,但它一次只能处理列表视图的一项。我想动态更改listview的每个imageview项。我所做的。我是朝着正确的方向走,还是应该尝试其他方法。请任何人向我推荐。我们将非常感谢您的帮助..提前感谢: 这是我的getView代码- final AQuery recycle

我有一个自定义列表视图,其中使用了四个项目,一个imageview和三个TextView。对于列表中的每个imageview,我有五个图像uri,我想在一定的时间内动态地更改特定imageview项的图像。我应用线程来动态更改图像,但它一次只能处理列表视图的一项。我想动态更改listview的每个imageview项。我所做的。我是朝着正确的方向走,还是应该尝试其他方法。请任何人向我推荐。我们将非常感谢您的帮助..提前感谢:

这是我的getView代码-

final AQuery recycle = aq.recycle(view);

final Handler mHandler = new Handler();

// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {

           animate_slide(recycle , currentimageindex);
           currentimageindex++;

        if(currentimageindex > 4){
            currentimageindex = 0;
                    }
            }
        };
        Timer timer = new Timer();

        timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {

                   mHandler.post(mUpdateResults);

                  }

            }, delay, period);
还有我调用的动画方法-

private void animate_slide(AQuery recycle ,int ci) {

                            if(ci == 0){
                                Log.d("00000000000000","----------"+ci);
                                recycle.id(R.id.avatar).progress(R.id.progress).image(ApplicationConstants.IMG_URL_SUFFIX+picture.get(currentimageindex), true, true, 100, 0, null, AQuery.FADE_IN);
                            }else if(ci == 1){
                                Log.d("11111111111111","----------"+ci);
                                recycle.id(R.id.avatar).progress(R.id.progress).image(ApplicationConstants.IMG_URL_SUFFIX+picture1.get(currentimageindex), true, true, 100, 0, null, AQuery.FADE_IN);
                            }else if(ci == 2){
                                Log.d("2222222222222222","----------"+ci);
                                recycle.id(R.id.avatar).progress(R.id.progress).image(ApplicationConstants.IMG_URL_SUFFIX+picture2.get(currentimageindex), true, true, 100, 0, null, AQuery.FADE_IN);
                            }else if(ci == 3){
                                Log.d("3333333333333333","----------"+ci);
                                recycle.id(R.id.avatar).progress(R.id.progress).image(ApplicationConstants.IMG_URL_SUFFIX+picture3.get(currentimageindex), true, true, 100, 0, null, AQuery.FADE_IN);
                            }else if(ci == 4){
                                Log.d("00000000000000","----------"+ci);
                                recycle.id(R.id.avatar).progress(R.id.progress).image(ApplicationConstants.IMG_URL_SUFFIX+picture4.get(currentimageindex), true, true, 100, 0, null, AQuery.FADE_IN);

                            }

                        }

您可以在getView xml文件中使用Gallary
你可以在那里做一些工作,你不需要把事情弄得那么复杂。我想只有列表中的第一项才有动画,对吗

我建议不要使用新的runnable,并像这样更改getView我假设代码中的currentimageindex是该项在ListView中的位置:

编辑:我想出了一个更简单的解决办法 我们不需要任何其他线程。 在getView中放入此代码,它将自动触发动画:

    // At first we load the animation 
    Animation slideAnimation = AnimationUtils.loadAnimation(context , R.anim.fade_in);
    slideAnimation.setRepeatMode(Animation.INFINITE);

    slideAnimation.setAnimationListener(new AnimationListener(){

        @Override
        public void onAnimationStart(Animation arg0) {/* Nothing*/}

        @Override
        public void onAnimationEnd(Animation animation) {
            yourImageView.setImageResource(R.drawable.newResource);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // Setting a delay after each animation.
            // This is the time between two animations.
            animation.setStartOffset(period);
        }

    });

    yourImageView.startAnimation(slideAnimation);
最后,不要忘记取消动画,因为我们说的是slideAnimation.setRepeatModeAnimation.INFINITE;。我建议在适配器类中添加此方法:

public void onDestroy() {
    slideAnimation.cancel();
}
在你的活动中:

    @Override
    public void onDestroy() {
        super.onDestroy();
        yourListAdapter.onDestroy();
    }

希望能有所帮助:

我正在使用与静态值相同的进程,但它工作正常。。但为什么不使用动态值呢?是否为每个新膨胀的视图调用getView代码?你能提供完整的getView代码吗?
    @Override
    public void onDestroy() {
        super.onDestroy();
        yourListAdapter.onDestroy();
    }