animate listView childs only once they appear

前端 未结 1 1747
既然无缘
既然无缘 2021-02-09 06:08

I have a listView with about 20 items (dynamic items). I want to animate these items first they show up to user. something like Google+ cards. There are some points that I want

相关标签:
1条回答
  • 2021-02-09 06:51

    I've just tried this and it seems to meet all of your requirements:

    boolean[] animationStates;
    
    public void YourConstructor(...) {
        ...
        animationStates = new boolean[data.size()];
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // (Re)Use the convertView
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.popup_list_item, parent, false);
            if (!animationStates[position]) {
                Log.e("TAG", "Animating item no: " + position);
                animationStates[position] = true;
                Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.fade_in);
                animation.setStartOffset(position*500);
                convertView.startAnimation(animation);
            }
        }
        // Use convertView here
        return convertView;
    }
    

    Here's my fade_in.xml file if you're interested:

    <set
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true">
        <alpha
            android:duration="1000"
            android:fromAlpha="0.0"
            android:toAlpha="1.0"/>
    </set>
    
    0 讨论(0)
提交回复
热议问题