【问题标题】:ListView - animation when adding new rowListView - 添加新行时的动画
【发布时间】:2017-01-24 16:02:05
【问题描述】:

我只是想在列表视图中为“添加”方法创建动画。这很好用,但动画也可以通过从列表视图中删除项目来触发。

所以

insert to index 0 -> "item 1" -> animation
insert to index 0 -> "item 2" -> animation
insert to index 0 -> "item 3" -> animation 

结果

item 3 
item 2
item 1

现在我想删除“项目 1”...动画当然是在索引 0 上触发的(项目 3 -> 开始动画)

我怎么知道这是删除方法?

private static void blink(final View v) 
{
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(300);
    animation.setStartOffset(20);
    animation.setRepeatMode(Animation.REVERSE);
    animation.setRepeatCount(Animation.INFINITE);
    v.setAnimation(animation);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            v.setAnimation(null);
        }
    }).start();
}

适配器

@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent)
{
    LayoutInflater inflater = LayoutInflater.from(getContext());
    View view = inflater.inflate(R.layout.alert_custom_row, parent, false);

    if(position == 0) // HERE some like isNewRow()?
        blink(view);

    return view;
}

活动

adapter.insert("item", 0);
adapter.notifyDataSetChanged();

非常感谢您帮助我。

【问题讨论】:

    标签: android listview animation


    【解决方案1】:

    如果没有另一个“列表”对象与适配器的 getCount() 比较的项目数,我将不知道如何确定您是在添加还是删除它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 2014-05-29
      • 2015-07-25
      • 1970-01-01
      相关资源
      最近更新 更多