很长的问题可能是一个简短的答案。
我有一系列图像(在网格视图中显示),当按下按钮时,我会使用 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 :(得分: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();
}
}
}
仍然欢迎其他/更好的解决方案,