#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Animated Object Disappears


    Hello,
    I am currently working on some applications with animations and fear I yet have not fully understood this topic, as for me strange things sometimes happen.
    I am using C# with the Xamarin Studio to develop for Android, so I beg your pardon for posting C# and not Java code, but I think just the syntax differs slightly and I would be very happy if some of you still looked into this.
    So my first question would be if this effect also can be seen when using Java, and then secondly of course if yes what is the reason.

    I broke my project down into just a few lines demonstrating the effect: I have 2 imageviews next to each other in a tablerow. These imageviews are then moved down with an ObjectAnimator (the right one lower than the left one, so they do not meet). Then the left imageview is moved to the position of the right image and vice versa. Now the left image disappears when reaching its final position (Img2.Left). However, if I just slightly change the final position (Img2.Left - 1), this effect does not occur. What is the cause for this? I test on my Samsung Galaxy S3 with the newest Android and Xamarin version, here is the complete code:

    Code:
    using System;
    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;
    using Android.Animation;
    
    namespace ReproduceSameLeft
    {
    	[Activity (Label = "ReproduceSameLeft", MainLauncher = true)]
    	public class MainActivity : Activity
    	{
    
    		protected override void OnCreate (Bundle bundle)
    		{
    			base.OnCreate (bundle);
    
    			TableLayout Layout = new TableLayout (this);
    			Layout.Orientation = Orientation.Horizontal;
    
    			TableRow Tr1 = new TableRow (this);
    			// Tr1.SetBackgroundColor (Android.Graphics.Color.Blue);
    			Tr1.SetMinimumHeight (200);
    			Tr1.SetClipToPadding (false);
    			Tr1.SetClipChildren (false);
    
    			ImageView Img1 = new ImageView (this);
    			Img1.SetMinimumWidth (50);
    			Img1.SetMaxWidth (50);
    			Img1.SetMinimumHeight (50);
    			Img1.SetMaxHeight (50);
    			Img1.SetImageResource (Resource.Drawable.Test);
    			Img1.SetAdjustViewBounds (true);
    			Img1.SetScaleType (ImageView.ScaleType.FitXy);
    			Tr1.AddView (Img1);
    
    			ImageView Img2 = new ImageView (this);
    			Img2.SetMinimumWidth (50);
    			Img2.SetMaxWidth (50);
    			Img2.SetMinimumHeight (50);
    			Img2.SetMaxHeight (50);
    			Img2.SetImageResource (Resource.Drawable.Test);
    			Img2.SetAdjustViewBounds (true);
    			Img2.SetScaleType (ImageView.ScaleType.FitXy);
    			Tr1.AddView (Img2);
    		
    			Layout.AddView (Tr1);
    
    			Button Btn1 = new Button (this);
    			Btn1.Click += (object sender, EventArgs e) => {
    
    				ObjectAnimator Down1 = ObjectAnimator.OfInt (Img1, "Top", 0, 60);
    				Down1.SetDuration(500);
    				ObjectAnimator Down2 = ObjectAnimator.OfInt (Img2, "Top", 0, 150);
    				Down2.SetDuration(500);
    				AnimatorSet Down = new AnimatorSet ();
    				Down.Play (Down1).With (Down2);
    
    				ObjectAnimator Move1 = ObjectAnimator.OfInt (Img1, "Left", Img1.Left, Img2.Left);
    				Move1.SetDuration(500);
    				ObjectAnimator Move2 = ObjectAnimator.OfInt (Img2, "Left", Img2.Left, Img1.Left);
    				Move2.SetDuration(500);
    				AnimatorSet Move = new AnimatorSet ();
    				Move.Play(Move1).With(Move2);
    
    				AnimatorSet AS = new AnimatorSet();
    				AS.Play(Down).Before(Move);
    				AS.Start ();
    			};
    			Layout.AddView(Btn1);
    
    			SetContentView (Layout);
    		}
    	}
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0
    And then I have another problem matching the same headline. The animated object also disappears when in a textview the number of lines changes. In the following example after a click on Button1 the imageview is moved down. When clicking Button2, new lines are added to the textview and the imageview disappears from the screen:

    Code:
    using System;
    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;
    using Android.Animation;
    
    namespace ReproduceNewLine
    {
    	[Activity (Label = "ReproduceNewLine", MainLauncher = true)]
    	public class MainActivity : Activity
    	{
    
    		protected override void OnCreate (Bundle bundle)
    		{
    			base.OnCreate (bundle);
    
    			TableLayout Layout = new TableLayout (this);
    			Layout.Orientation = Orientation.Horizontal;
    
    			TableRow Tr1 = new TableRow (this);
    			// Tr1.SetBackgroundColor (Android.Graphics.Color.Blue);
    			Tr1.SetMinimumHeight (200);
    			Tr1.SetClipToPadding (false);
    			Tr1.SetClipChildren (false);
    
    			ImageView Img1 = new ImageView (this);
    			Img1.SetMinimumWidth (50);
    			Img1.SetMaxWidth (50);
    			Img1.SetMinimumHeight (50);
    			Img1.SetMaxHeight (50);
    			Img1.SetImageResource (Resource.Drawable.Icon);
    			Img1.SetAdjustViewBounds (true);
    			Img1.SetScaleType (ImageView.ScaleType.FitXy);
    			Tr1.AddView (Img1);
    
    			Layout.AddView (Tr1);
    
    			TextView TextView1 = new TextView (this);
    			Layout.AddView (TextView1);
    			Button Btn1 = new Button (this);
    			Btn1.Click += (object sender, EventArgs e) => {
    				ObjectAnimator Down1 = ObjectAnimator.OfInt (Img1, "Top", 0, 60);
    				Down1.SetDuration(500);
    				Down1.Start();
    			};
    			Layout.AddView(Btn1);
    
    			Button Btn2 = new Button (this);
    			Btn2.Click += (object sender, EventArgs e) => {
    				TextView1.Text = "Test" + System.Environment.NewLine + "Test";
    			};
    			Layout.AddView(Btn2);
    
    			SetContentView (Layout);
    		}
    	}
    }
    Thanks!

    Oh btw I posted the same post also in the Xamarin forum (http://forums.xamarin.com/discussion/10871/animated-object-disappears#latest), but unfortunately did not get a reply there.

IMN logo majestic logo threadwatch logo seochat tools logo