2016-08-14 25 views
0

Ok, damit ich Blick auf mein Layout programmatisch mich hinzufügen und sie dann zu animieren, die Ansichten korrekt hinzuzufügen erscheinen, aber wenn ich die Animation zu starten tut es scheint, hier zu arbeiten ist der Code:eine dynamisch hinzugefügt Ansicht Animieren

   Random random = new Random(); 
      final ImageView imageView = new ImageView(getApplicationContext()); 
      final ViewGroup vg = (ViewGroup) animationLayout; 

      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
      //params.topMargin = screenHeight; 
      params.leftMargin = random.nextInt(screenWidth); 

      vg.addView(imageView,params); 

      imageView.setImageResource(R.drawable.musical); 
      imageView.setColorFilter(getResources().getColor(R.color.colorPrimary)); 
      float randomSize = random.nextFloat() * (1.5f - 0.5f) + 0.5f; 
      imageView.setScaleX(randomSize); 
      imageView.setScaleY(randomSize); 


      ObjectAnimator animator = ObjectAnimator.ofInt(imageView, "translationY",0, -screenWidth); 
      animator.setDuration(15000); 
      animator.setInterpolator(new LinearInterpolator()); 
      animator.addListener(new Animator.AnimatorListener() { 
       @Override 
       public void onAnimationStart(Animator animator) { 

       } 

       @Override 
       public void onAnimationEnd(Animator animator) { 
        Log.e("removed", "true"); 
        vg.removeView(imageView); 
       } 

       @Override 
       public void onAnimationCancel(Animator animator) { 

       } 

       @Override 
       public void onAnimationRepeat(Animator animator) { 

       } 
      }); 
      animator.start(); 

Was könnte dazu führen, dass die Animation nicht funktioniert? die Ansicht entfernt wird, nachdem die Animation aber so ist über i

Antwort

0

ok verstehen nicht, die Antwort gefunden sieht aus wie ich wurde mit ObjectAnimator.ofInt() statt ObjectAnimator.ofFloat()

+0

Haben Sie sich an den 'LayoutTransition' https://developer.android.com /reference/android/animation/LayoutTransition.html für eine alternative Lösung? – liminal

+0

@liminal Dies ist kein Layout-Übergang. Ich füge dynamisch mehrere ImageViews in einem Layout im Hintergrund des angezeigten Inhalts hinzu, um die Auswirkungen eines sich bewegenden Hintergrunds zu erzielen –

Verwandte Themen