안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요. 애니메이션 공부중에 난관에 부딧혔습니다.
TranslateAnimation 를 사용하여 버튼의 위치를 옮겼습니다. 하지만 이동된 버튼에 event 가 붙질 않고
원래 위치(xml에 정의) 에 event 가 붙어있습니다.
분명 버튼이 이동되었고, 이전위치에는 버튼이 보이질 않는데 event 가 붙어 있습니다. 신기하네요.
이동된 버튼에 event 를 붙이는 방법이나 원래위치에 event를 옮기는 방법이 있을까요?
소스는..
public class MainActivity extends Activity {
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Animation anim = new TranslateAnimation(0, 200, 0, 0);
anim.setDuration(1000);
anim.setFillAfter(true);
bt.startAnimation(anim);
}
});
}
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Animation anim = new TranslateAnimation(0, 200, 0, 0);
anim.setDuration(1000);
anim.setFillAfter(true);
bt.startAnimation(anim);
}
});
}
}

안드로이드 개발자입니다.
요렇게 해보세요..
Animation anim = new TranslateAnimation(0, 200, 0, 0);
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
// 이동할 위치를 넣어서 layout을 다시 잡으세요..
bt.layout(left, top, right, bottom);
}
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
});
bt.startAnimation(anim);