2011-08-16 173 views
0

我對我的項目有要求。我希望我的相對佈局從頂部滑到底部..Can請人給我這個動畫布局

感謝一些幫助, Keerthi

+0

檢查本http://stackoverflow.com/questions/20374823/android-animate-my-relative-layout-from-bottom-to-top-and-top-to-bottom-using-tr –

回答

0

其簡單,

創建一個佈局,並在佈局上應用翻譯動畫。在XML使佈局不可見的,在你的代碼,根據烏拉圭回合的需要

 <RelativeLayout 
android:id="@+id/linearLayout3" 
android:layout_width="wrap_content" 
android:layout_height="220dip" 
android:orientation="vertical" 
android:layout_marginTop="480dip" 
> 
</RelativeLayout>  

Java代碼使其可見

改變這個XML是這樣

  Animation movement5; 
    layout3 = (LinearLayout) findViewById(R.id.linearLayout3); 


       layout3.setVisibility(true); USE THIS LINE //EDITED 

movement5 = AnimationUtils.loadAnimation(this,R.layout.animation_test5); 
    movement5.reset(); 
     movement5.setfillafter(true); 
    movement5.setAnimationListener(this); 
     layout3.startAnimation(movement5); 

animation_test5.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="-300%" 
    android:toYDelta="100%" android:duration="3000" android:zAdjustment="normal" /> 
+0

move.setAnimationListener(this); ...我得到setAnimationListener錯誤..你能告訴我什麼是這個對象 – Keerthiraj

+1

你的活動應該實現AnimationListner – Randroid

+0

但是當我這樣做時,它要求我添加未實現的方法..添加後我應該編輯這些方法.. – Keerthiraj

1

使用類TranslateAnimation

public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 

在這裏,您可以給來自YDelta和toYDelta的頂部到底部動畫值。然後通過類TranslateAnimation的對象調用方法setDuration(以毫秒爲單位的時間)和setFillAfter(true)。