Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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
Android tween动画之前显示的可绘制_Android_Animation_Drawable_Android Animation - Fatal编程技术网

Android tween动画之前显示的可绘制

Android tween动画之前显示的可绘制,android,animation,drawable,android-animation,Android,Animation,Drawable,Android Animation,我有一个活动(A),在计算后启动另一个活动(B)。我的问题是,当活动B启动时,在开始tween动画之前,应该从左向右移动的箭头(从.33缩放到1)首先显示很短的一段时间。最终的结果是,在开始设置动画之前,会出现令人烦恼的全尺寸可绘制的闪烁 一切似乎都表明问题与动画文件(.xml)有关,而与java类无关。这可以在我删除行arrowImage.startAnimation(arrowExtent)时观察到在以下代码中: protected void arrowAnimation(Animation

我有一个活动(A),在计算后启动另一个活动(B)。我的问题是,当活动B启动时,在开始tween动画之前,应该从左向右移动的箭头(从.33缩放到1)首先显示很短的一段时间。最终的结果是,在开始设置动画之前,会出现令人烦恼的全尺寸可绘制的闪烁

一切似乎都表明问题与动画文件(.xml)有关,而与java类无关。这可以在我删除行
arrowImage.startAnimation(arrowExtent)时观察到在以下代码中:

protected void arrowAnimation(Animation arrowExtent) {
        // TODO Auto-generated method stub

        arrowImage.setImageResource(R.drawable.arrowimage);
        arrowImage.startAnimation(arrowExtent);
        arrowExtent.setFillAfter(true);
我尝试了以下方法:

  • 对可绘制对象使用setImageDrawable而不是setImageResource
  • 设置
    arrowImage.setFillBefore(false)
  • 如有任何建议,我们将不胜感激

    动画xml如下所示:

    <?xml version="1.0" encoding="utf-8"?>
    
    
    

    
    

    当活动开始时,应使
    ImageView
    xml
    onCreate()
    中不可见,当动画开始时,应将其更改为可见

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // referencing views etc. 
        arrowImage.setVisibility(View.INVISIBLE);
        // or make image invisible in xml
    }
    
    protected void arrowAnimation(Animation arrowExtent) {
        arrowExtent.setAnimationListener(new AnimationListener() {
    
            @Override
            public void onAnimationStart(Animation animation) {
                arrowImage.setVisibility(View.VISIBLE);
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) { }
    
            @Override
            public void onAnimationEnd(Animation animation) { }
        });
    
        arrowImage.setImageResource(R.drawable.arrowimage);
        arrowImage.startAnimation(arrowExtent);
    }
    

    感谢您的建议,我忘了提到为了能够在活动B中使用上下文菜单,我必须将动画从
    onCreate(
    )移动到
    onWindowsFocusChanged()
    。我之前在
    onCreate()
    中尝试了动画,并获得了相同的结果。建议的代码并不能解决问题,我注意到当
    arrowImage.startAnimation(arrowExtent)
    被称为可绘制时,无论是可见还是不可见,都会被绘制出来。此外,我尝试了以下操作,以查看我是否观察到了一些提示,我做到了。我在
    arrowAnimation()
    中尝试了
    arrowExtent.setStartOffset(1000)
    。结果是:1。箭头的闪烁图像可绘制。2.一秒钟都没有。3.以缩放的箭头图像开始并随着动画的进行而变换的动画。因此,我的直觉告诉我,动画xml文件在开始之前正在屏幕上绘制箭头图像。我正在发布动画xml。
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // referencing views etc. 
        arrowImage.setVisibility(View.INVISIBLE);
        // or make image invisible in xml
    }
    
    protected void arrowAnimation(Animation arrowExtent) {
        arrowExtent.setAnimationListener(new AnimationListener() {
    
            @Override
            public void onAnimationStart(Animation animation) {
                arrowImage.setVisibility(View.VISIBLE);
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) { }
    
            @Override
            public void onAnimationEnd(Animation animation) { }
        });
    
        arrowImage.setImageResource(R.drawable.arrowimage);
        arrowImage.startAnimation(arrowExtent);
    }