2012-08-09 111 views
2

我有這樣動畫上查看

enter image description here

視圖當用戶點擊喜歡說「奧迪」的任何按鈕。

我想要的是看到前面的這個觀點與動畫像 enter image description here

我已經試過被

我做一個佈局是這樣的(只是爲了測試動畫)

<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" > 

<LinearLayout 
    android:id="@+id/hideLayout" 
    android:layout_width="200dip" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/buttonLayout" 
    android:background="#f0f" 
    android:visibility="gone" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/buttonLayout" 
    android:layout_width="200dip" 
    android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/btn_showView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Show View" /> 
</LinearLayout> 

,然後讓動畫像

Animation showView=(Button)findViewById(R.id.btn_showView);

和我的動畫文件

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <translate 
     android:duration="300" 
     android:fromYDelta="100%p" 
     android:toYDelta="0" /> 

</set> 

然後

showView=(Button)findViewById(R.id.btn_showView); 

    showView.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      hideLayout.startAnimation(animShow); 
      animShow.setAnimationListener(new AnimationListener() { 

       @Override 
       public void onAnimationStart(Animation animation) { 
        hideLayout.setVisibility(View.VISIBLE); 

       } 

       @Override 
       public void onAnimationRepeat(Animation animation) { 
        // TODO Auto-generated method stub 

       } 

       @Override 
       public void onAnimationEnd(Animation animation) { 
        hideLayout.setVisibility(View.VISIBLE); 

       } 
      }); 

     } 
    }); 

這是工作,但不是我多麼希望。 text View來自底部。我希望我的形象展現出我想要的。

在此先感謝。

+0

試試這個android:fromYDelta =「 - 100%p」代替android:fromYDelta =「100%p」 – blessenm 2012-08-09 09:17:30

+0

不,它會從屏幕的-ve底部開始。 – 2012-08-09 09:21:12

+0

@MMohsinNaeem你有任何解決方案? – 2012-08-14 16:51:35

回答

1

我找到了android> = 3的解決方案。0,Object Animator

我修正了視圖的高度,因爲它對我來說不是問題。

我提出兩個視圖

1)頂視圖寬度修復高度100dip(需要被動畫)使其不可見

2)底部視圖修復高度100dip(可見)

3)當我點擊showView我打電話以下行

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(topLayout, 
      "y", 100, 0); 
objectAnimator.addListener(new AnimatorListener() { 

     @Override 
     public void onAnimationStart(Animator animation) { 
      // TODO Auto-generated method stub 
      topLayout.setVisibility(View.VISIBLE); 
      showView.bringToFront(); 
     } 

     @Override 
     public void onAnimationRepeat(Animator animation) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationEnd(Animator animation) { 

     } 

     @Override 
     public void onAnimationCancel(Animator animation) { 
      // TODO Auto-generated method stub 

     } 
    }); 
      objectAnimator.setDuration(500); 
    objectAnimator.start(); 

可能會幫助一些之一。 :)

0

TextView來自底層,因爲代碼中的android:fromYDelta="100%p"。如果你希望你的TextView從原來的位置移動,就要使用下面的代碼:

<?xml version="1.0" encoding="utf-8"?> 
    <set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:interpolator="@android:anim/linear_interpolator" > 

     <translate 
      android:duration="500" 
      android:toYDelta="-66%" 
      android:fromYDelta="0%" /> 

    </set> 

更改按照您的要求值-66%

從圖像什麼我能猜到是你想要父佈局的Marke: Audi滑入和滑出。 爲此,您將必須爲父佈局(您想要滑入和滑出的佈局的父級)設置動畫,並且還必須修復兩個視圖的高度比。然後在動畫結束時,將上視圖的可見性更改爲GONE

+0

它會從上到下。我想要的是從下到上。 – 2012-08-09 09:30:45

+0

抱歉,我的錯誤只是將fromto的值顛倒過來。編輯我的代碼。 – vKashyap 2012-08-09 09:37:11

+0

仍然沒有成功:( – 2012-08-09 09:54:35

0

儘量讓水庫 - >動畫文件夾

slide_in_bottom.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromYDelta="-100%p" android:toYDelta="0%p" 
android:duration="@android:integer/config_longAnimTime" /> 

slide_in_top.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromYDelta="100%p" android:toYDelta="0%p" 
android:duration="@android:integer/config_longAnimTime"/> 

slide_out_bottom.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="@android:integer/config_longAnimTime" 
    android:fromYDelta="0" 
    android:toYDelta="100%p" /> 

slide_out_top.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromYDelta="0" android:toYDelta="-100%p" 
android:duration="@android:integer/config_longAnimTime" /> 

overridePendingTransition(R.anim.slide_in_top,R.anim.slide_out_top);

+1

我知道這一點,但它對'fill_parent'情況有效 – 2012-08-09 09:55:51

+0

是的,它是有效的。 – 2012-08-13 05:34:41