Android text view transition

2019-03-02 13:59发布

问题:

I am new to android development. I want to create a splash screen with two text views. In this splash screen I want two transitions

1) Text View 1 transition from top to center 2) text View 2 transition from bottom to center

Both transitions should be performed at the same time

how to achieve this ?

Thanks,

回答1:

Creat an xml file in your anim folder name bottom_to_top.xml

  <?xml version="1.0" encoding="utf-8"?>
        <set xmlns:android="http://schemas.android.com/apk/res/android">
            <translate
                android:duration="2000"
                android:fillAfter="true"
                android:fromYDelta="100%p"
                android:toYDelta="0%p" />
        </set>

and your oncreat you add this

        TextView textview= (TextView) findViewById(R.id.textview);
        Animation bottomToTop = AnimationUtils.loadAnimation(this, R.anim.bottom_to_top);
        textview.startAnimation(bottomToTop);

and from top to bottom animation

create an xml file by name top_bottom.xml in your anim folder

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="2000"
        android:fillAfter="true"
        android:fromYDelta="-100%p"
        android:toYDelta="0%p" />
</set>

and place in java

            TextView textview2= (TextView) findViewById(R.id.textview2);
            Animation topTobottom = AnimationUtils.loadAnimation(this, R.anim.top_bottom);
            textview2.startAnimation(topTobottom );

Hope this helps you