将动画添加到Android中的列表视图

将动画添加到Android中的列表视图,第1张

概述我想为列表视图的项目设置动画.目前,我在添加新项目时,将过渡动画应用于列表项.但这不是我想要实现的动画.当我在当时的列表视图中添加一个新的项目时,我想要的是整个列表视图将一个位置移动到新增的项目中. 目前我使用的代码是: set = new AnimationSet(true); animation = new AlphaAnimation(0.0f, 1.0f); animat 我想为列表视图的项目设置动画.目前,我在添加新项目时,将过渡动画应用于列表项.但这不是我想要实现的动画.当我在当时的列表视图中添加一个新的项目时,我想要的是整个列表视图将一个位置移动到新增的项目中.

目前我使用的代码是:

set = new AnimationSet(true);    animation = new AlphaAnimation(0.0f,1.0f);    animation.setDuration(50);    set.addAnimation(animation);    animation = new TranslateAnimation(        Animation.relative_TO_SELF,0.0f,Animation.relative_TO_SELF,-1.0f,0.0f    );    animation.setDuration(150);    set.addAnimation(animation);    LayoutAnimationController controller = new LayoutAnimationController(set,1.0f);    l.setLayoutAnimation(controller);    l.setAdapter(ListAdaptor);

然后通过按钮onClick添加项目

l.startLayoutAnimation();

任何其他建议来实现这样的动画.

解决方法 我得到了解决方案.我在自定义适配器的getVIEw方法中为每个添加的元素设置动画.
public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {        VIEw v = convertVIEw;        if (v == null) {            LayoutInflater vi = (LayoutInflater) getActivity()                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);            v = vi.inflate(R.layout.simple_List_item_1,null);        }        ListData o = List.get(position);        TextVIEw tt = (TextVIEw) v.findVIEwByID(R.ID.toptext);        tt.setText(o.content);        Log.d("ListTest","position : "+position);       if(flag == false) {        Animation animation = AnimationUtils.loadAnimation(getActivity(),R.anim.slIDe_top_to_bottom);        v.startAnimation(animation);}        return v;    }

从而实现了我所说的动画.

总结

以上是内存溢出为你收集整理的将动画添加到Android中的列表视图全部内容,希望文章能够帮你解决将动画添加到Android中的列表视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1132654.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存