How does TranslateAnimation works android?

I went through

TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

but still confused about how does Translate animation works.

  • Android Media Player Restart Audio After Calling Stop
  • When I load ADT why do I receive the error “The Android SDK requires Android Developer Toolkit version XX.X.X or above?”
  • Android: Custom Spinner Layout
  • Android - Prevent white screen at startup
  • javax.net.ssl.sslpeerunverifiedexception no peer certificate
  • Detect if user interacts with phone?
  • any one please explain how it works i read docs which saying

    fromXDelta  Change in X coordinate to apply at the start of the animation
    toXDelta    Change in X coordinate to apply at the end of the animation
    fromYDelta  Change in Y coordinate to apply at the start of the animation
    toYDelta    Change in Y coordinate to apply at the end of the animation 
    

    but still its not clear to me how its working.

    EDIT: I have a Button and a LinearLayout without any child in that when i am clicking on the Button i want to generate a dynamic TextView and animate that TextView to the LinearLayout the number of TextViews will depend upon the number of click on the Button.

    Related posts:

    Exception raised during rendering: Unable to locate mode 0
    How to transfer files between Android applications running on the same device?
    Database Access in Android
    SyncAdapter without a ContentProvider
    Rx Java mergeDelayError not working as expected
    What's the default Hex Color of the Holo.Light.DarkActionBar ActionBar
  • Gradle: add dependency for a specific flavour of the library
  • cocos2d-x-2.1.4 : error: format not a string literal and no format arguments
  • android-sdk/tools/ant/build.xml:698: null returned: 1
  • how to get the IP of the wifi hotspot in Android?
  • What is orderInCategory in ActionBar menu item & why it is use for..?
  • File sharing between Android phone and a PC
  • 2 Solutions collect form web for “How does TranslateAnimation works android?”

    AFAIK,there would be relative connection between this.

    That is,if you want to translate a hidden textview from right of screen to left of screen,on click of a button,you actually need to translate it from 100% of X-direction(right side of screen) to 0% of X-direction(left side of screen).

    At this point,you don’t need to change Y-direction at all.so that would be 0% for both the options.So finally,you will have:

    fromXDelta 100%

    toXDelta 0%

    fromYDelta 0%

    toYDelta 0%

    you can restrict view of the component by setting this percentages between 0 to 100,as per your requirement.

    Similarly,if you need to translate your component on Y-direction as well,then you need to change 0% to some other value.

    Hope,its clear to you now.

    EDIT :

    for your requirement,you need to override onclick of button-1,and there you can control button-2’s visibility as well as translation.

    create animation file in anim folder in your res.

    translate_button.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <!-- translating button from right to left -->
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:shareInterpolator="false">
        <translate
            android:fromXDelta="100%" android:toXDelta="0%"
            android:fromYDelta="0%" android:toYDelta="0%"
            android:duration="900"
        />
    </set>
    

    now,in your activity file,

    ...
    
    // ll  is linear layout containing button_2
    //counter is used to manage visibility of button_2 on click of button_1,i.e.1st click-button_2 would be visible,on 2nd click on button_1,it would be invisible.
    
    //you can change behavior as per your need
    
    button_2.setVisibility(View.GONE);
    button_1.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View arg0) {
    
            if(counter<1)
            {
                counter++;                  
                button_2.setVisibility(View.VISIBLE);
                Animation anim=AnimationUtils.loadAnimation(context, R.anim.translate_button);
                button_2.startAnimation(anim);
            }
            else
            {
                counter=0;
                button_2.setVisibility(View.GONE);
            }
        }
    });
    ll.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View arg0) {
    
            if(counter==1)
            {
                counter=0;
                button_2.setVisibility(View.GONE);
            }
        }
    });
    
    ...
    

    With TranslateAnimation you can create an animation to control an object.

    With TranslateAnimation you’re able to control the position of an object.
    You pass this 4 parameters, which stand for the X and Y coordinates.

    By Example you want to move an object to the right, you would do something like:
    TranslateAnimation(0.0f, 1.0f, 0.0f, 0.0f)

    (or use Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF)

    We only use the X coordinate now, because we are doing now an easy “LeftToRight” animation-move.

    Change in X coordinate to apply at the start of the animation
    toXDelta (0.0f)    
    
    Change in X coordinate to apply at the end of the animation (1.0f)
    

    = 1 to right

    Maybe take a look at http://en.wikipedia.org/wiki/Coordinate_system

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.