改变可见性时的Android动画



很长的问题,可能是一个简短的答案。

我有一系列的图像(显示在网格视图中),当按钮被按下时,我使用AnimationDrawable类进行动画。
动画的代码片段;

AnimationDrawable mAnimation;
view.setImageDrawable(null);
Random randomGenerator = new Random();
int rand = randomGenerator.nextInt(6);
BitmapDrawable frame0 = (BitmapDrawable)context.getResources().getDrawable(spinImages.get(0));
BitmapDrawable frame1 = (BitmapDrawable)context.getResources().getDrawable(spinImages.get(1));
BitmapDrawable last = (BitmapDrawable)context.getResources().getDrawable(endImages.get(rand));
mAnimation = new AnimationDrawable();
mAnimation.isOneShot();
for (int i=0; i < spinNumber; i++) {
    mAnimation.addFrame(frame0, spinDuration);
    mAnimation.addFrame(frame1, spinDuration);
}
mAnimation.addFrame(last, spinDuration);
view.setBackgroundDrawable(mAnimation);
view.setTag(rand);
mAnimation.start();

还有一个旋转器,它将根据所选值过滤图像,设置其中一些不可见(到目前为止,所有工作都很好)。

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    int index = arg0.getSelectedItemPosition();
    String[] filterOptions;
    filterOptions = getResources().getStringArray(R.array.spn_options);
    // hide all below filter value
    GridView gridView = (GridView) findViewById(R.id.grid_view);
    for (int i=0; i < ((ViewGroup)gridView).getChildCount(); ++i) {
        View nextChild = ((ViewGroup)gridView).getChildAt(i);
        nextChild.setVisibility(View.VISIBLE);
        if (nextChild instanceof ImageView) {
            // get tag
            if (Integer.parseInt(nextChild.getTag().toString()) < arg2) {
                nextChild.setVisibility(View.INVISIBLE);
            }
            nextChild.getTag();
        }
    }
}

问题是当旋转显示全部被选中时,我应用setVisibility(View.VISIBLE)对图像;这使得图像重新出现,但再次触发动画。我希望图像重新出现,只显示动画的最终状态。

任何想法?

我已经破解了一种方法,通过设置图像资源之前使其不可见。

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    int index = arg0.getSelectedItemPosition();
    String[] filterOptions;
    filterOptions = getResources().getStringArray(R.array.spn_options);
    // hide all below filter value
    GridView gridView = (GridView) findViewById(R.id.grid_view);
    for (int i=0; i < ((ViewGroup)gridView).getChildCount(); ++i) {
        View nextChild = ((ViewGroup)gridView).getChildAt(i);
        nextChild.setVisibility(View.VISIBLE);
        if (nextChild instanceof ImageView) {
            // get tag
            if (Integer.parseInt(nextChild.getTag().toString()) < arg2) {
                ImageView iv = (ImageView) nextChild;
                iv.setImageResource(R.drawable.one);
                iv.setTag(nextChild.getTag().toString());
                iv.setVisibility(View.INVISIBLE);
            }
            nextChild.getTag();
        }
    }
}

我仍然欢迎其他/更好的解决方案,