私は、複合画面に、RelativeLayoutを使って画面の右上隅に付いているボタンがいくつか混在しています。私はこのビューを右に動かすには、 "open-close"ボタンをクリックし、ユーザーがそのボタンの1つを選択/クリックするか、または "close-close"ボタンで再びクリックしてから、見えなくなる。問題は、それが左にアニメートしてから元の場所に戻ることです!この問題を解決するにはどうすればよいですか?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);
}
}
任意のアイデア?
感謝を!それは動作しますが、私の「クローズド・クローズ」ボタンはこのような状況ではクリックに反応しないようです。私は正しい? –
プレハニカムアニメーションフレームワークは、レイアウトの視覚的な部分だけを移動します。物理的な場所は同じで、あなた自身で移動する必要があります。 HoneycombはAnimatorクラスを導入しました。具体的にはPropertyAnimatorが導入されました。これはオブジェクトのアニメーション化と物理的な移動の両方を行います。 – DeeV
私はAndroid 2.1で作業していますので、実際のオブジェクトをスナップショットだけでなくアニメーションで移動するにはどうすればよいですか? –