2014-07-21 49 views
0

在android应用程序中,我有一个imageview。我想把另一张图片放在上面。当用户触摸图像时,顶部图像将像窗帘一样向上滑动,以显示其下面的图像。当用户移开他的手指时,我将转到另一页android imageview窗帘风格动画

我该如何实现这一目标?

enter image description here

基本上我知道我必须实现OnTouch监听和WORL对“ACTION_DOWN”和“ACTION_UP”案件。但是我不知道如何做到这一幕帷幕动画?因为翻译将翻译整个图像,而不仅仅是在图像画布中。

感谢所有帮助

回答

1

有可能通过具有两个ImageView小号FrameLayout下实现它:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/parent"> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/solid_blue" 
     android:id="@+id/img_back"/> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/solid_green" 
     android:id="@+id/img_front"/> 
</FrameLayout> 

而且在活动中加入onTouchListener和平移前的ImageView会做的工作:

ObjectAnimator mSlideAnim; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.curtainstyle); 

    final ImageView imgFront = (ImageView) findViewById(R.id.img_front); 

    FrameLayout parent = (FrameLayout) findViewById(R.id.parent); 
    parent.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      int action = event.getAction(); 
      switch (action) { 
       case MotionEvent.ACTION_DOWN: 
        if (mSlideAnim == null) { 
         triggerSlideUpAnimation(imgFront); 
        } 
        break; 
       case MotionEvent.ACTION_MOVE: 
        break; 
       case MotionEvent.ACTION_UP: 
       case MotionEvent.ACTION_CANCEL: 
        goToAnotherPage(); 
        break; 
      } 
      return true; 
     } 
    }); 
} 

private void triggerSlideUpAnimation(ImageView imgFront) { 
    int height = imgFront.getHeight(); 
    mSlideAnim = ObjectAnimator.ofFloat(imgFront, "translationY", 0, -height); 
    mSlideAnim.setDuration(300); 
    mSlideAnim.start(); 
} 

private void goToAnotherPage() { 
    Toast.makeText(this, "Go to another page", Toast.LENGTH_SHORT).show(); 
}