화면의 절반 정도에서부터 맨 아래까지가는 원형의 간단한 애니메이션이 있습니다. 그것은 천천히 쓰러지고 나의 의도는 그것을 클릭 할 때 무언가를 할 수 있도록 클릭 할 수 있도록하는 것입니다. 처음부터 정지 위치까지 아무 곳이나 클릭 할 수 있기를 바랍니다.애니메이션 도중 이미지와 함께 이동하는 onClick 핸들러를 얻으려면 어떻게해야합니까?
원은 ImageView
으로 구현되었으며 clickable
및 onClick
속성을 추가했습니다. 원이으로 시작된 곳을 누르면 onClick
처리기가 예상대로 작동하지만 애니메이션 중에 이미지를 "추적"하지 않는 것 같습니다.
AnimationListener
클래스를 발견하고 나는 애니메이션이
onAnimationEnd()
핸들러를 통해 종료 할 때 내
ImageView
's의 좌표를 업데이트 할 수 있었지만 애니메이션이 실행되는 동안이 작업을 수행 할 수있는 방법이 될 것 같지 않습니다.
애니메이션이 움직이기 때문에 onClick
핸들러 위치를 업데이트하는 데 사용할 수있는 클래스/메소드가 있습니까? 그렇지 않은 경우 목표를 달성하기 위해 사용해야하는 다른 유형의 애니메이션이 있습니까?
관련 코드 :
내 이미지 뷰에 대한 XML 레이아웃 :
ImageView bubble = (ImageView) findViewById(R.id.bubble);
Animation bubblefall = AnimationUtils.loadAnimation(this, R.anim.bubble_fall);
bubblefall.setAnimationListener(new MyAnimationListener());
bubble.startAnimation(bubblefall);
자바 다음 onCreate
방법의 자바 소스 코드를 애니메이션을 시작하는
<ImageView
android:id="@+id/bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"
android:src="@drawable/bubble"
android:clickable="true"
android:onClick="popBubble"
android:contentDescription="bubble"
android:layout_below="@id/sun"
/>
내 AnimationListener를 설정하는 소스 코드 :
private class MyAnimationListener implements AnimationListener{
@Override
public void onAnimationEnd(Animation arg0) {
ImageView local = (ImageView) findViewById(R.id.bubble);
local.clearAnimation();
local.offsetTopAndBottom(50);
애니메이션 XML : 당신은 사용할 수 있습니다
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:duration="10000"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<translate
android:fromYDelta="10%p"
android:toYDelta="60%p" />
<alpha
android:fromAlpha="0.7"
android:toAlpha="0.7" />
</set>