2014-10-19 149 views
1

我試圖做一個應用程序,在第一個屏幕中,圖像(應用程序的名稱)飛入背景,並固定到某個位置。我是新來的機器人,並會感謝任何幫助。屏幕上的圖像動畫

我一直在使用setAnimationListener()嘗試:

public class Pageone extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fragment_main); 

    final ImageView imageView=(ImageView)findViewById(R.id.image); 
    Animation anim1 = new TranslateAnimation(0, 0, 1024, 824); 
    anim1.setDuration(3000); 
    anim1.setFillAfter(true); 

    anim1.setAnimationListener(new Animation.AnimationListener() { 
       @Override 
       public void onAnimationStart(Animation animation) { 

       } 

       @Override 
       public void onAnimationEnd(Animation animation) { 
        Animation anim2 = new TranslateAnimation(0, 0, 824, 1024); 
        anim2.setDuration(3000); 
        anim2.setFillAfter(true); 
        imageView.clearAnimation(); 
        imageView.startAnimation(anim2); 
       } 

       @Override 
       public void onAnimationRepeat(Animation animation) { 

       } 
      }); 


    imageView.startAnimation(anim1); 


    } 
    } 

和XML頁面 -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.meeting.MainActivity$PlaceholderFragment" 
    android:background="@drawable/tapregister" > 

    <ImageView 
    android:id="@+id/image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:src="@drawable/meet" 
    /> 





    </RelativeLayout>' 

當運行在Android虛擬設備管理器中的應用,我覺得是在佈局中看到固定的圖像部分。

+0

該代碼發生了什麼? – joao2fast4u 2014-10-19 00:38:55

+0

圖像「見面」顯示在xml圖形佈局中,靜止圖像在中間,沒有轉換,因爲我工作的是bieng,在eclipse的android虛擬設備上運行時顯示.. – ashish 2014-10-19 16:10:50

+0

要動畫的哪個ImageView? ?見面還是形象? – joao2fast4u 2014-10-19 17:30:44

回答

0

你不需要兩個動畫來做你想做的。您只需要一個將ImageView從底部移動到屏幕中心的動畫。

因此,請刪除您的anim1.setAnimationListener()代碼。將Ydelta值更改爲從位置Y + 300(例如)開始並結束於位置Y + 0(您的佈局原始位置)。這會將ImageView放置在屏幕底部,比初始位置低300 px,並將其移動到中心,這是您的佈局初始位置。像這樣:

final ImageView imageView=(ImageView)findViewById(R.id.image); 
Animation anim1 = new TranslateAnimation(0,0,300,0); 
anim1.setDuration(3000); 
anim1.setFillAfter(true); 
imageView.startAnimation(anim1);