Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

animation - How to build Animator slide up/down in XML for android?

I've been trying to find out how to build an animator (xml) that will cause a slide up and slide down effect. How would that work? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Make a folder anim in the res folder of the project. Now add slide_up.xml for slide_up animation. Then add slide_down.xml for slide down animation.

Code for slide_down.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <translate android:fromXDelta="0" android:toYDelta="-1000" android:duration="1500"/>
</set>

Code for slide_up.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <translate android:fromXDelta="0" android:toYDelta="1000" android:duration="1500"/>
</set>

Then load the animation in onCreate method consequently:

Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);

To start it attach it to object you want to be animated:

ImageView img = (ImageView) findViewById(R.id.img);
img.startAnimation(slideUp);

Hope I've helped you. :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...