Tom*_*sso 20 animation android
我正在尝试实现http://developer.android.com/guide/topics/resources/animation-resource.html("动画资源")中描述的"超空间"补间动画- 但它似乎不起作用书面.当我运行应用程序时,我只是在应用程序标题栏下面看到一个空白视图.我究竟做错了什么?
根据这个例子,这是我的代码.我创建了res/anim/hyperspace_jump.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
<set
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="700">
<scale
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="0.6"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400" />
<rotate
android:fromDegrees="0"
android:toDegrees="-45"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400" />
</set>
</set>
Run Code Online (Sandbox Code Playgroud)
我还创建了一个layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
最后我有一个活动:
package com.tomoreilly.geology;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image = (ImageView) findViewById(R.id.ImageView01);
Animation hyperspaceJump =
AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
image.startAnimation(hyperspaceJump);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行应用程序时,我没有看到任何动画.我是否遗漏了"动画资源"示例中未涉及的一些细节?
谢谢,汤姆
Aur*_*bon 11

要添加不同的答案,您还可以尝试通用Tween引擎来动画您的Android UI.实际上,你的动画需要相当多的XML格式,如下所示:
Timeline.createSequence()
// First, set your pivot (Tween.set() works instantly)
.push(Tween.set(image, ViewAccessor.PIVOT_XY).target(0.5f, 0.5f))
// Then, animate your scale and rotation as you want
.push(Tween.to(image, ViewAccessor.SCALE_XY, 0.7f).target(1.4f, 0.6f))
.beginParallel()
.push(Tween.to(image, ViewAccessor.SCALE_XY, 0.4f).target(0, 0))
.push(Tween.to(image, ViewAccessor.ROTATION, 0.4f).target(-45))
.end()
// Finally, start the animation!
.start();
Run Code Online (Sandbox Code Playgroud)
当您有大量序列操作时,它可能更具可读性.该引擎针对Android进行了大量优化,特别是对于游戏而言,并没有分配任何东西,以提供最佳性能.
它完全是开源的,有大量文档记录,并且使用Apache-2许可证发布.
如果你想要,你可以试试Android演示 :)
小智 5
您的imageview必须在xml或您的活动中定义源.
XML:
<ImageView android:id="@+id/ImageView01"
android:src="@drawable/someimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
Run Code Online (Sandbox Code Playgroud)
活动:
ImageView image = (ImageView) findViewById(R.id.ImageView01);
image.setImageResource(R.drawable.some_image);
Run Code Online (Sandbox Code Playgroud)
小智 -1
我猜 ViewFlipper 是必需的。因为当你想要在动画之间制作动画时,你需要 ViewFlipper 来执行动画。
做以下事情。我想解决问题。
创建新的 XML 文件并在其中添加 ViewFlipper 选项卡...
当您想要制作动画时,使用 include 选项卡来包含所有其他布局。
并使用以下代码
flipper = (ViewFlipper) findViewById(R.id.flipper);
Button button1 = (Button) findViewById(R.id.Button01); // Button in one activity
Button button2 = (Button) findViewById(R.id.Button02); // Button in second activity
// Other Methods
private Animation inFromRightAnimation() {
// Animation inFromRight = new TranslateAnimation(
/*
* Animation inFromRight = new ScaleAnimation(
* Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
* 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
* Animation.RELATIVE_TO_PARENT, 0.0f);
*/
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
private Animation outToLeftAnimation() {
// Animation outtoLeft = new TranslateAnimation(
/*
* Animation outtoLeft = new
* ScaleAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
* Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
* 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
*/
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
private Animation inFromLeftAnimation() {
// Animation inFromLeft = new TranslateAnimation(
/*
* Animation inFromLeft = new
* ScaleAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
* Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
* 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
*/
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
private Animation outToRightAnimation() {
// Animation outtoRight = new TranslateAnimation(
/*
* Animation outtoRight = new
* ScaleAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
* Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
* 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
*/
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66369 次 |
| 最近记录: |