【问题标题】:Is there a way to stop Listview from reloading on datachange?有没有办法阻止 Listview 在 datachange 上重新加载?
【发布时间】:2015-04-11 16:48:20
【问题描述】:

我正在尝试实现从列表视图中删除项目的动画。然后项目的动画从左到右(删除时离开屏幕)我在其下方的视图上运行动画以向上移动并卡入到位,但问题是 listview 检测到删除时列表闪烁。 我运行动画的代码是:

 Animation an = AnimationUtils.loadAnimation(MainActivity.this, R.anim.offscreen);
                            itemc.setHasTransientState(true);
                            itemc.startAnimation(an);
                            final Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    l.remove(positionc);
                                    adapter.remove(positionc);

                                   // adapter.notifyDataSetChanged();



                                }
                            }, 1050);
                            //animate below views to position



                            ArrayList<View> vl=new ArrayList<View>();
                            //for loop runs and saves all the views below the deleted view 
                            for(int i=position+1;i<=listView.getLastVisiblePosition();i++)
                            {
                                vl.add(listView.getChildAt(i));
                            }
                            //one by one animation is performed on all the views 
                            ListIterator itr=vl.listIterator();
                            while(itr.hasNext())
                            {

                                View v =(View)itr.next();
                                v.setHasTransientState(true);
                                v.animate().setDuration(500).translationYBy(-      itemc.getHeight());//iteam is the view deleted 
                            }

【问题讨论】:

    标签: android listview android-listview android-animation


    【解决方案1】:

    我找到了一种阻止 android 在 datasetchange 上的 listview 上运行默认动画的方法(想要实现我自己的动画) 只需添加:

    listView.setLayoutTransition(null);
    

    这将阻止列表视图运行其默认动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 2021-12-25
      • 2019-08-05
      • 2016-01-16
      • 2011-02-14
      • 2021-08-25
      相关资源
      最近更新 更多