I'd like to translate an image from left to right on emulator using android animation. I'm new to android animation. How could I do that?
我想使用Android动画在模拟器上从左到右翻译图像。我是android动画的新手。我怎么能这样做?
Thanks.
3 个解决方案
#1
58
ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this);
tv.setText("Animation");
moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
moveLefttoRight.setDuration(1000);
moveLefttoRight.setFillAfter(true);
button = new Button(this);
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
button.setText("PressMe");
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tv.startAnimation(moveLefttoRight);
}
});
ll.addView(tv);
ll.addView(button);
setContentView(ll);
is one way of doing it.
这是一种做法。
#2
30
Move an image from left to right and right to left by using Android TranslateAnimation
使用Android TranslateAnimation从左到右,从右到左移动图像
ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
0.0f, 0.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
animation.setDuration(5000); // animation duration
animation.setRepeatCount(5); // animation repeat count
animation.setRepeatMode(2); // repeat animation (left to right, right to left )
//animation.setFillAfter(true);
img_animation.startAnimation(animation); // start animation
you can find more details from here
你可以在这里找到更多细节
#3
-1
Add this code R.anim folder
添加此代码R.anim文件夹
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="800" />
</set>
#1
58
ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this);
tv.setText("Animation");
moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
moveLefttoRight.setDuration(1000);
moveLefttoRight.setFillAfter(true);
button = new Button(this);
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
button.setText("PressMe");
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tv.startAnimation(moveLefttoRight);
}
});
ll.addView(tv);
ll.addView(button);
setContentView(ll);
is one way of doing it.
这是一种做法。
#2
30
Move an image from left to right and right to left by using Android TranslateAnimation
使用Android TranslateAnimation从左到右,从右到左移动图像
ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
0.0f, 0.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
animation.setDuration(5000); // animation duration
animation.setRepeatCount(5); // animation repeat count
animation.setRepeatMode(2); // repeat animation (left to right, right to left )
//animation.setFillAfter(true);
img_animation.startAnimation(animation); // start animation
you can find more details from here
你可以在这里找到更多细节
#3
-1
Add this code R.anim folder
添加此代码R.anim文件夹
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="800" />
</set>