我有几个图像动画在flipper中,当下一个按钮被按下下一个图像应该来自右侧和当前图像应该从左侧出去,类似地,如果后退被按下前一个应该来自右侧和当前图像应该出去。我想在动画中左进右出,左出右出,也要记住堆的大小,有没有人有解决方案?我使用了下面的代码
nbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (current_shown_index < list.length - 1) {
current_shown_index++;
bkbtn.setVisibility(View.VISIBLE);
View view = inflater.inflate(R.layout.view_flipper_item, null);
ImageView iv = (ImageView) view.findViewById(R.id.iv_flipper_item);
iv.setImageResource(list[current_shown_index]);
Log.v("count", vFlipper.getChildCount() + "flipper length");
if (vFlipper.getChildCount() == 3) {
vFlipper.removeViewAt(0);
}
vFlipper.addView(view);
vFlipper.setInAnimation(inFromRightAnimation());
vFlipper.setOutAnimation(outToLeftAnimation());
vFlipper.showNext();
}
}
});
bkbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (current_shown_index > 0) {
int diff = 2;
if (vFlipper.getChildCount() == 3 ){
vFlipper.removeViewAt(2);
}
View viewb = inflater.inflate(R.layout.view_flipper_item, null);
ImageView iv = (ImageView) viewb.findViewById(R.id.iv_flipper_item);
if(current_shown_index == 1 ){
diff = 1;
}else{
iv.setImageResource(list[current_shown_index-diff ]);
}
vFlipper.addView(viewb, 0);
current_shown_index--;
}else{
bkbtn.setVisibility(View.GONE);
}
vFlipper.setInAnimation(inFromLeftAnimation());
vFlipper.setOutAnimation(outToRightAnimation());
vFlipper.showPrevious();
}
});发布于 2012-06-22 19:53:34
我会给你一个起始指针:
final Animation outToLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
final Animation inFromRight = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
final Animation outToRight = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_left);
final Animation inFromLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_right);现在将它们与ViewFlipper中的setInAnimation和setOutAnimation一起使用。
发布于 2012-06-22 19:53:55
为了在ViewFlipper中实现输入和输出动画,可以使用setInAnimation()和setOutAnimation()方法。
为例:
viewFlipper.setInAnimation(AnimationUtils.loadAnimation(
mContext, android.R.anim.slide_in_right));
viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(
mContext, android.R.anim.slide_out_right));
/* Where - mContext is Context object
*/发布于 2012-06-23 02:21:47
ViewSwitcher可以为您处理这一点,here视图切换器在行动中
您还可以在此处找到附带源代码的example
https://stackoverflow.com/questions/11155599
复制相似问题