2013-03-22 68 views
0

可能是简短答案的长问题。更改Visiblity时的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);这会使图像重新出现,但会再次触发动画。我希望图像重新出现,仅显示动画的最终状态。

任何想法?

回答

0

我已经通过设置图像资源,使其不可见之前绕过它的方式。

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(); 
     } 
    } 
} 

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