0

imageview と 3 つの textview の 4 つのアイテムが使用されている 1 つのカスタム リスト ビューがあります。リストのすべてのイメージビューに対して5つのイメージURIがあり、特定のイメージビューアイテムの一定期間内にイメージを動的に変更したいと考えています。画像を動的に変更するためのスレッドを適用しましたが、一度にリストビューの1つのアイテムにしか機能しません。リストビューのすべてのイメージビュー項目を動的に変更したい。私がやること。私は正しい方向に進んでいますか、それとも何か他のことを試す必要があります.誰かが私に提案してください.助けは非常に高く評価されます..事前に感謝します:)

これが私の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);

                            }

                        }
4

2 に答える 2

0

getView xmlファイルでGallaryを使用でき、そこでいくつかの作業を行うことができます

于 2014-04-10T14:01:59.480 に答える
0

それほど複雑にする必要はありません。リストの最初のアイテムだけがアニメーション化されると思いますが、そうですか?

新しいランナブルを使用せず、次のように変更することをお勧めします(コードでは、アイテムの位置が であるgetView()と想定しています):currentimageindexListView

// The view holder for better ListView
private class ViewHolder {
    TextView text1, text2, text3;
    ImageView image;
}

@Override
public View getView(int position, View view, ViewGroup parent) {

    final ViewHolder holder;
    if (view == null) {
        holder = new ViewHolder();
        /* Initialize views and add them to  the ViewHolder
         * 
         * ....
         * 
        */
        // Setting the position as a tag, so we can get it in the runnable
        holder.image.setTag(position);
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                animate_slide(aq.recycle(holder.image), (int) holder.image.getTag());
            }

        }, when, period);
        view.setTag(holder);
    } else holder = (ViewHolder) view.getTag();

    /* do what you want with the texts...
     * 
     * ....
     * 
    */  

    return view;

}

編集:より簡単な解決策を見つけました。:) 他のスレッドは必要ありません。内部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.setRepeatMode(Animation.INFINITE);。アダプター クラスにこのメソッドを追加することをお勧めします。

public void onDestroy() {
    slideAnimation.cancel();
}

そしてこれはあなたの活動で:

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

それが役に立てば幸い :)

于 2014-07-18T07:58:00.550 に答える