2011-03-16 74 views
1

嘿! 基本上,我有這個文字的這個小動畫,當一個人點擊屏幕時「滑動」下來。翻譯動畫幫助不大

從上往下滑動需要6秒。

雖然滑動如果有人再次點擊屏幕,我想用另一個動畫,使它左/右或任何不同的動畫。 基本上,使用some_other_animation.xml將該translate.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> 

回答

1

嗯,你的「第二」的動畫不能使用XML定義,因爲它依賴於運行事件。您可以根據觸摸事件的位置在代碼中構建新的動畫。

+0

好點!我是一個新手..所以它滑過去了。謝謝! – Ryan 2011-03-24 04:20:07