2017-04-04 4 views
0

RelativeLayout에는 TextView 및 TextView 아래에 Button이 있고 다른 두 객체를 다루는 ImageView가 있습니다. 사용자가 액티비티를 열면 ImageView가 다른 항목을 포함해야합니다. 사용자가 이미지를 왼쪽 또는 오른쪽으로 스 와이프하면 사용자가 버튼을 조작하고 텍스트 필드를 읽을 수 있도록 해제해야합니다.안드로이드 dimsiss 스 와이프 제스처의 ImageView

온 클릭 리스너 클릭했을 때 이미지를 닫을 수 있었지만 요소를 삭제하기 위해 스 와이프 할 때 RecicleView와 같은 애니메이션을 원합니다.

답변

0

원하는 애니메이션을 onClick 이벤트에 추가 할 수 있습니다.

1) 생성 (또는 기존의 경우 추가) 입술 디렉토리 내부의 ANIM 폴더를 넣어 slide_animation.xml

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

    <translate 
     android:fromXDelta="0%p" 
     android:toXDelta="75%p" 
     android:duration="800" /> 
</set> 

2) 이미지 뷰의 온 클릭 동작이 코드를 추가

// Refer the ImageView like this 
imageView = (ImageView) findViewById(R.id.imageView); 

// Load the animation like this 
animSlide = AnimationUtils.loadAnimation(getApplicationContext(), 
        R.anim.slide_animation); 

// Start the animation like this 
imageView.startAnimation(animSlide); 

xml의 애니메이션 사양을 수정하여 원하는 효과를 얻을 수 있습니다.

그리고 AnimatorListener를 구현하면 애니메이션이 끝날 때 이미지 뷰를 닫을 수 있습니다.

animSlide.setListener(new AnimatorListenerAdapter() { 
     @Override 
     public void onAnimationEnd(Animator animation) { 
      super.onAnimationEnd(animation); 
      //remove image view from the layout 
     } 
    });