Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用TranslateAnimation时,ImageView将消失_Java_Android_Animation_Imageview_Transition - Fatal编程技术网

Java 应用TranslateAnimation时,ImageView将消失

Java 应用TranslateAnimation时,ImageView将消失,java,android,animation,imageview,transition,Java,Android,Animation,Imageview,Transition,我明白,这是当地的问题,但我和它斗争了一天,我想寻求你的帮助 我有这样一种“游戏”,用户可以通过swype移动项目,在这种情况下,我们是从上到下进行swype。项目是实际的图像视图 在第一幅图中,我们可以看到实际swype之前的7个项目 项目尽可能向下移动,直到他遇到另一个项目或字段边界(现在不可见) 在第二张图中,项目被向下移动了一次(只有那些没有移动障碍物的项目,其中4个) 第二次swype后项目的最终位置: 现在的问题是:我无法解释为什么,但确切地说,当我第一次从上到下键入并应用于将

我明白,这是当地的问题,但我和它斗争了一天,我想寻求你的帮助

我有这样一种“游戏”,用户可以通过swype移动项目,在这种情况下,我们是从上到下进行swype。项目是实际的图像视图

在第一幅图中,我们可以看到实际swype之前的7个项目

项目尽可能向下移动,直到他遇到另一个项目或字段边界(现在不可见)

在第二张图中,项目被向下移动了一次(只有那些没有移动障碍物的项目,其中4个)

第二次swype后项目的最终位置:

现在的问题是:我无法解释为什么,但确切地说,当我第一次从上到下键入并应用于将向下移动到新位置的实际动画的4个项目时,它们在中途消失并出现在新位置上

当我执行any其他swype时,向任何方向,任何项目都会设置动画,没有问题。当我把第二个字打到底的时候,一切都很顺利

我检查过了,动画做得很好,有正确的参数,动画中没有其他的ImageView,但是如果ImageView顶部有障碍物的话,有些东西正好覆盖了动画!这太奇怪了

所有需要的代码如下所示:

动画空洞

private void moveItem(final FieldItem item, final float x, final float y) {
                      // item to animate, transition X, transition Y
    final RelativeLayout.LayoutParams oldParams = (LayoutParams) item
            .getLayoutParams();

    TranslateAnimation animation = new TranslateAnimation(0.0f, x, 0.0f, y);
    animation.setDuration(500);
    animation.setFillAfter(true);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            item.invalidate();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {

            item.clearAnimation();

            //all following is just to remove old item from layout
            //and put new item on the place where animation should have ended
            //nothing which can affect, it works perfect with any other condition

            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    itemSize, itemSize);

            params.leftMargin = (int) (oldParams.leftMargin + x);
            params.topMargin = (int) (oldParams.topMargin + y);


            gView.rLayout.removeView(item);
            putItem(1, params);
            gView.rLayout.invalidate();

            //it's only ArrayList which contains copies of all Layout's children
            //of ImageView class, for providing field moves logic, can't affect
            //also recounts how many imageViews are in children of Layout
            updateField();

            //shows right margins, right amount of items on the field, they are always recounted depending of RelativeLayout children
            Log.i("my_log", "Pos change, from " + oldParams.leftMargin + "/" + oldParams.topMargin + " to " + params.leftMargin + "/" + params.topMargin);
            Log.i("my_log", "Size of field: " + field.size());
        }
    });

    item.startAnimation(animation);
}
此处使用的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clipChildren="false"
    android:orientation="vertical" >

    <com.crispy_chocolate.outofthebox.GameView
        android:id="@+id/game"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clipChildren="false" />

</RelativeLayout>


所以问题是-当在任何其他情况下,相同的方法都可以完全正常工作时,ImageView如何在动画的局部情况下甚至消失?也许会有人来帮助我。

显然,这是一个bug,因为如果我在屏幕底部放置任何imageview,或者编写一些文本,动画就会开始完全正常。奇怪