我有一个列表视图。我想添加一个动画,如果我选择一个列表项目,那么它将被删除,该项目下的其他项目将随着向上滑动动画向上移动。我已通过获取其子位置来完成线性布局,但我无法理解如何滑动listview的其余元素。请帮助向上滑动选定的列表视图项目的动画
下面是我在动态创建的线性布局动画代码
plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation animation1 = AnimationUtils.loadAnimation(getActivity(), R.anim.move);
final Animation animation2 = AnimationUtils.loadAnimation(getActivity(), R.anim.moveup);
这是该项目的动画制作上,我们点击
lay1.startAnimation(animation1);
这是代码动画休息的孩子向上滑动
final int i = lay1.getId() + 1;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
try {
LinearLayout l = (LinearLayout) layoutall.getChildAt(i);
l.startAnimation(animation2);
layoutall.removeView(lay1);
} catch (Exception e) {
//connectToDatabase();
}
}
}, 600);
更新代码 非常感谢。我能够实现这个功能,但问题是我在一个列表视图中使用了两个动画,但无法实现第一个动画。
我的列表项的代码就是我要刷上点击
viewHolder.accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeListItem(viewHolder.order_card_layout, position);
}
});
和代码动画左边,而为
protected void removeListItem(final View rowView, final int positon) {
// TODO Auto-generated method stub
final Animation animation = AnimationUtils.loadAnimation(rowView.getContext(), R.anim.move);
rowView.startAnimation(animation);
Animation.AnimationListener al = new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
ViewHolder vh = (ViewHolder) rowView.getTag();
//vh.needInflate = true;
}
@Override public void onAnimationRepeat(Animation animation) {}
@Override public void onAnimationStart(Animation animation) {}
};
collapse(rowView, al);
}
但问题是我的第一个动画不能正常工作,那就是
final Animation animation = AnimationUtils.loadAnimation(rowView.getContext(), R.anim.move);
rowView.startAnimation(animation);
新更新的代码 我能够实现这个功能,但问题是,我用了两个动画和想要做的关于该项目的第一个动画人,我点击,并在所有的列表项另一个动画但是我的问题是,我单击幻灯片右侧的项目,它也重新出现并向上滑动整个列表,但我希望我点击的项目将向右滑动,其余部分将滑动。
我的列表项的代码就是我要刷上点击
viewHolder.accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeListItem(viewHolder.order_card_layout, position);
}
});
和代码动画左边,而为
保护无效removeListItem(最终查看rowView,最终诠释当前位置){ // TODO自动生成方法存根
final Animation animation = AnimationUtils.loadAnimation(rowView.getContext(), R.anim.move);
rowView.startAnimation(animation);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
try {
Animation.AnimationListener al = new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
ViewHolder vh = (ViewHolder) rowView.getTag();
//vh.needInflate = true;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
};
collapse(rowView, al);
} catch (Exception e) {
//connectToDatabase();
}
}
}, 600);
}
private void collapse(final View v, Animation.AnimationListener al) {
final int initialHeight = v.getMeasuredHeight();
Animation anim = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
}
else {
v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
v.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
if (al!=null) {
anim.setAnimationListener(al);
}
anim.setDuration(600);
v.startAnimation(anim);
}
非常感谢。我能够实现这个功能,但问题是我在一个列表视图中使用了两个动画,但无法实现第一个动画。我的代码是: –