Results 1 to 3 of 3
  1. #1
    blackdiz is offline Member
    Join Date
    Apr 2012
    Posts
    16
    Rep Power
    0

    Default A problem about clearAnimation().

    I write a little App to make a textview rotate and translate and control the animation by two buttons.
    And I use clearAnimation() to stop the animation ,but when I click the stop button , the textview stops and also disappears, is that normal?
    What I want to do is when I stop the animation , the textview can go back to the position when the App starts.
    If I can't do this function with clearAnimation() mehod , can you give me some hints for how to achieve this function?Thank you very much.
    Here is my Activity Code
    Java Code:
    package com.example.ex05_04v2;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.animation.*;
    import android.widget.*;
    
    public class MainActivity extends Activity {
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		findViews();
    	}
    
    	private void findViews() {
    		Button start = (Button)findViewById(R.id.start);
    		Button stop = (Button)findViewById(R.id.stop);
    		
    		start.setOnClickListener(new OnClickListener() {
    
    			public void onClick(View v) {
    				TextView tv = (TextView) findViewById(R.id.textView1);
    				Animation ani = AnimationUtils.loadAnimation(getApplicationContext(),
    						R.anim.scale_animation);
    				tv.startAnimation(ani);
    			}
    		});
    
    		stop.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				TextView tv = (TextView) findViewById(R.id.textView1);
    				tv.clearAnimation();
    			}
    		});
    	}
    }
    and here is my animation XML:
    Java Code:
    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/linear_interpolator">
    	<rotate android:fromDegrees="0"
               android:toDegrees="360"
               android:pivotX="50%"
               android:pivotY="50%"
               android:repeatCount="-1"
               android:duration="1000" />
    	<translate android:fromXDelta="0%p"
    	    android:toXDelta="80%p"
    	    android:fromYDelta="0%p"
    	    android:toYDelta="80%p"
    		android:duration="10000" />
     </set>
    I would approciate it you can help , and hope you can understand my poor English.
    Best Regards,thank you

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

    Default Re: A problem about clearAnimation().

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    blackdiz is offline Member
    Join Date
    Apr 2012
    Posts
    16
    Rep Power
    0

    Default Re: A problem about clearAnimation().

    Quote Originally Posted by DarrylBurke View Post
    Sorry,I didn't notice that, would you delete this post ,please, thank you

Similar Threads

  1. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  2. Replies: 9
    Last Post: 09-21-2010, 04:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •