2011-03-16 4 views
1

안녕하세요! 기본적으로, 사람이 화면을 클릭 할 때 "슬라이드"하는이 텍스트의 작은 애니메이션이 있습니다.번역 애니메이션에 대한 도움이 거의 없습니다.

위쪽에서 아래쪽으로 슬라이드하는 데 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> 

답변

1

음은, 당신의 "초"애니메이션은 XML로 정의 할 수 없습니다. 터치 이벤트의 위치에 따라 코드로 새 애니메이션을 만들 수 있습니다.

+0

좋은 지적! 나는 초보자이다. 그래서 그것은 과거를 미끄러 뜨렸다. 감사! – Ryan

관련 문제