gpt4 book ai didi

android - 选定 ListView 项的向上滑动动画

转载 作者:行者123 更新时间:2023-11-29 01:13:50 27 4
gpt4 key购买 nike

我有一个 ListView 。我想添加一个动画,如果我选择一个列表项,它将被删除,并且该项目下方的其余项目将通过向上滑动动画向上移动。我已经通过获取其子位置使用线性布局完成了此操作,但我无法理解如何向上滑动 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);

这是动画rest child向上滑动的代码

            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);

更新代码多谢。我能够实现此功能,但问题是我在一个 ListView 中使用了两个动​​画,但无法实现第一个动画。

我想在点击时向左滑动的列表项的代码

       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);

}
});

动画代码是

protected void removeListItem(final View rowView, final int positon) { //TODO 自动生成方法 stub

    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);
}

最佳答案

这是与您的要求相关的代码,试试这个

https://github.com/paraches/ListViewCellDeleteAnimation

下载代码并运行。

如果你想看演示而不是看这个视频,

http://www.youtube.com/watch?v=bOl5MIti7n0

关于android - 选定 ListView 项的向上滑动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41177433/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com