저는 컴파운드 뷰가 화면의 오른쪽 상단 구석에 RelativeLayout으로 연결된 버튼이 섞여 있습니다. 이 뷰는 "닫힌 상태"버튼을 클릭 할 때 오른쪽으로 움직이기를 원하고 사용자가 해당 버튼 중 하나를 선택/클릭하거나 "닫은 상태"버튼을 다시 클릭 할 때까지 그대로 남아서 오른쪽으로 움직여야합니다. 보이지 않게된다. 문제는 왼쪽으로 움직 인 다음 다시 원래 위치로 이동한다는 것입니다. 이 문제를 해결하려면 어떻게해야합니까?Android TranslateAnimation animation
코드 :
public class AlarmCommandComponent extends LinearLayout {
ImageButton carOffButton;
ImageButton carOnButton;
ImageButton armButton;
ImageButton disArmButton;
ImageButton openCloseButton;
LayoutAnimationController controller;
Animation animation;
public AlarmCommandComponent(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.car_alarm_view, this);
openCloseButton = (ImageButton) findViewById(R.id.alarmOpenCloseButton);
AnimationSet set = new AnimationSet(true);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, //fromXType
0.0f, //fromXValue
Animation.RELATIVE_TO_SELF, //toXType
-1.0f, //toXValue
Animation.RELATIVE_TO_SELF, //fromYType
0.0f, //fromYValue
Animation.RELATIVE_TO_SELF, //toYType
0.0f); //toYValue
animation.setDuration(500);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);
this.setLayoutAnimation(controller);
this.setPadding(0, 7, 7, 10);
this.setBackgroundColor(Color.BLACK);
openCloseButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
openCloseButton_onClick(v);
}
});
}
public void openCloseButton_onClick(View v) {
this.startAnimation(animation);
}
}
어떤 생각?
감사합니다 -
이 API이 글을 읽을 벌집 이전에 존재하는 애니메이션 제약 조건에 대한 자세한 내용을 알고 -
은 내부 onAnimationEnd 이렇게 애니메이션 리스너 &를 설정! 작동하지만 내 "닫기 버튼"이이 상황에서 클릭에 응답하지 않는 것 같습니다. 내가 맞습니까? –
프리 허니 콤 애니메이션 프레임 워크는 레이아웃의 시각적 부분 만 이동합니다. 물리적 위치는 동일하게 유지되므로 직접 이동해야합니다. Honeycomb은 Animator 클래스를 소개했습니다. 특히 PropertyAnimator는 객체를 움직이게하고 물리적으로 움직입니다. – DeeV
Android 2.1에서 작업 중이므로 실제 객체를 애니메이션으로 이동하려면 어떻게해야합니까? –