Небольшая помощь с анимацией перевода - PullRequest
1 голос
/ 16 марта 2011

Эй! По сути, у меня есть небольшая анимация этого текста, которая «скользит» вниз, когда человек нажимает на экран.

Скольжение сверху вниз занимает 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" />

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>

1 Ответ

1 голос
/ 23 марта 2011

Хм, ваша "вторая" анимация не может быть определена с помощью xml, так как она зависит от события во время выполнения. Вы можете создать новую анимацию в коде, основанную на местоположении события касания.

...