2012-08-09 125 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