翻译动画的帮助不大

发布于 2024-10-21 21:58:38 字数 3027 浏览 1 评论 0原文

嘿! 基本上,我有这个文本的小动画,当人们单击屏幕时,它会“滑动”下来。

从上滑到下需要6秒。

当它滑动时,如果有人再次单击屏幕,我想将该动画替换为另一个动画,使其向左/向右或任何不同的方向移动。 基本上,从该位置(而不是从头开始)将translate.xml 动画替换为some_other_animation.xml。

(我最终的想法是让它“爆炸”)。 任何帮助表示赞赏。

我的文件:Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/root"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"     android:gravity="top|center">
    <TextView android:id="@+id/animatedText" android:layout_height="wrap_content"     android:text="@string/hello" android:layout_width="wrap_content"></TextView>
</LinearLayout>

Strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="hello">Just a sample string!</string>
 <string name="app_name">Ryan Sample</string>

</resources>

动画类:

package com.ryan.test.animsxx;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AnimationActivity extends Activity {
 /** Called when the activity is first created. */
 @Override public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 final Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
 a.reset();
 final TextView rText = (TextView) findViewById(R.id.animatedText);

 LinearLayout layout = (LinearLayout) findViewById(R.id.root);
 layout.setOnClickListener(new OnClickListener() {
 @Override public void onClick(View v) {
 rText.startAnimation(a);

 }
 });

 }
}

Translate.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromXDelta="0%" android:toXDelta="0%" android:fromYDelta="0%"
 android:toYDelta="300%" android:duration="6000" android:zAdjustment="bottom" />

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.ryan.test.animsxx"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AnimationActivity"
 android:label="@string/app_name">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>

</application>
</manifest>

Hey!
Basically, I have this little animation of this text that "slides" down when a person clicks the screen.

It takes 6 seconds to slide from top to the bottom.

While it is sliding if someone clicks the screen again, I want to replace that animation with another animation which makes it go left/right or anything different.
Basically, replace the translate.xml animation with some_other_animation.xml right from that spot (not from the beginning).

(My eventual idea is to make it "explode").
Any help appreciated.

My files: Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/root"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"     android:gravity="top|center">
    <TextView android:id="@+id/animatedText" android:layout_height="wrap_content"     android:text="@string/hello" android:layout_width="wrap_content"></TextView>
</LinearLayout>

Strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="hello">Just a sample string!</string>
 <string name="app_name">Ryan Sample</string>

</resources>

Animation class:

package com.ryan.test.animsxx;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AnimationActivity extends Activity {
 /** Called when the activity is first created. */
 @Override public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 final Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
 a.reset();
 final TextView rText = (TextView) findViewById(R.id.animatedText);

 LinearLayout layout = (LinearLayout) findViewById(R.id.root);
 layout.setOnClickListener(new OnClickListener() {
 @Override public void onClick(View v) {
 rText.startAnimation(a);

 }
 });

 }
}

Translate.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromXDelta="0%" android:toXDelta="0%" android:fromYDelta="0%"
 android:toYDelta="300%" android:duration="6000" android:zAdjustment="bottom" />

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.ryan.test.animsxx"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AnimationActivity"
 android:label="@string/app_name">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>

</application>
</manifest>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七秒鱼° 2024-10-28 21:58:38

嗯,你的“第二个”动画不能用 xml 定义,因为它依赖于运行时事件。您可以根据触摸事件的位置在代码中构造一个新的动画。

Um, your "second" animation cannot be defined with xml, since it depends on a runtime event. You could construct a new animation in code, based on the location of the touch event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文