开发者

How to move a Image from (x1,y1) to (x2,y2) linearly (using Animations) [Android]

开发者 https://www.devze.com 2023-02-27 05:01 出处:网络
I need to know how to move a image from one location to another location smoothly. In some tutorials they have asked to move it pixel by pixel calling invalidate() function after waiting for a small t

I need to know how to move a image from one location to another location smoothly. In some tutorials they have asked to move it pixel by pixel calling invalidate() function after waiting for a small time duration.

But isnt there any other way to do it.?

But i need to开发者_JAVA技巧 animate it dynamically. Think that i need to move some image to the location where person touches on screen. I need it to be do using Java, not from XML


You can create a animation on XML, load it and use on your view.

Consider it's the file hide.xml (on the res/anim folder)

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

Then in your Activity you load it and apply to the View you want to translate.

Animation hide = AnimationUtils.loadAnimation(this, R.anim.hide);
yourView.startAnimation(hide);
0

精彩评论

暂无评论...
验证码 换一张
取 消