listview点击item动画效果

Android 码拜 9年前 (2015-11-13) 1790次浏览
问题如下图:
listview点击item动画效果
第一次点击时,动画效果没错。但第二次点击时,两个白色的item都动了。貌似是上次的动画又播了一遍,求指导决方法。
重写了baseAdapter,class MusicListAdapter extends BaseAdapter。
getView如下,仅设置了选中字体和非选中字体静态效果。

class MusicListAdapter extends BaseAdapter{
                @Override
                public int getCount() {
                        return list.size();
                }
                @Override
                public Object getItem(int arg0) {
                        return list.get(arg0);
                }
                @Override
                public long getItemId(int arg0) {
                        return arg0;
                }
                @Override
                public View getView(int arg0, View arg1, ViewGroup arg2) {
                        if (arg1 == null) {
                                arg1 = getLayoutInflater().inflate(R.layout.list_item,
                                                null);
                        }
                        TextView tv_music_name = (TextView) arg1
                                        .findViewById(R.id.textView1_music_name);        
                        tv_music_name.setTextColor(Color.WHITE);
                        tv_music_name.setText(list.get(arg0).substring(18).replace(".mp3", " ").replace("_", "-"));
                        if(arg0==FIXMUSICINDEX){//位置FIXMUSICINDEX固定被选中
                                tv_music_name.setAlpha(1);
                                tv_music_name.setTextColor(Color.rgb(30,144,255));
                                tv_music_name.setTextSize(25);
                                tv_music_name.setBackgroundResource(R.drawable.colorchange);
                                tv_music_name.setFocusable(true);//实现focus在列表
                                tv_music_name.requestFocus();
                        }
                        else if(arg0>=0&&arg0<getCount()){
                                tv_music_name.setTextColor(Color.argb(150,255,255,255));
                                tv_music_name.setShadowLayer(3F,1F,1F,Color.argb(255, 200, 200, 200));
                                tv_music_name.setTextSize(19);                
                                tv_music_name.setBackgroundResource(R.drawable.black);
                                tv_music_name.getBackground().setAlpha(0);
                        }        
                        if(arg0==getCount())
                                clickflag=0;
                        return arg1;
                }

listView的点击监听事件如下,写在oncreate()里,在这里定义了点击项动画

listView.setOnItemClickListener(new OnItemClickListener(){
                        @Override
                        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                        long arg3) {                
                                orienIndex=arg2-FIXMUSICINDEX;                                
                                updatemusiclist();
                                
                                if(orienIndex>0)
                                        arg0.startAnimation(textup);
                                else if(orienIndex<0)
                                        arg0.startAnimation(textdown);
                                clickflag=1;
                                listView.clearAnimation();
                                listView.getChildAt(currIndex).startAnimation(tbig);
                                if(clickflag==1){
                                        listView.getChildAt(recordpreviousindex).startAnimation(tsmall);
                                }        
                        }                                
                });

其中recordpreviousindex记录上次位置为4的item现在的位置。
这个listener在每次点击的时候执行了几次啊,为神马会在一次点击时有这么多动画

解决方案:50分
http://blog.csdn.net/bailyzheng/article/details/8536806
一般情况是notifyDataSetChanged,本人不知道你是属于数据源失效还是更改,请参考以上链接!
键盘应该是直接出发刷新然后在getView里面出发动画,但是你的onclick也手动出发刷新了应该是一样的,
不过onclick中你又手动去触发动画了,这点可能会有影响.
其实没必要这么复杂,简化一下逻辑吧

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明listview点击item动画效果
喜欢 (0)
[1034331897@qq.com]
分享 (0)