【发布时间】:2012-07-05 18:21:27
【问题描述】:
我有一个由一些按钮混合在一起的复合视图,这些按钮使用RelativeLayout 附加在屏幕的右上角。当我单击其上的“打开-关闭”按钮并保持在那里直到用户选择/单击其中一个按钮或再次单击“打开-关闭”按钮时,我希望该视图向右动画,然后它应该向右动画并且变得隐形。问题是它向左移动,然后又回到原来的位置!我应该怎么做才能解决这个问题?
代码:
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);
}
}
有什么想法吗?
【问题讨论】: