繁体   English   中英

Android:在for循环中为视图列表设置动画

[英]Android: animate a list of views in a for loop

我有一个自定义对象的数组列表。 每个自定义对象都对应于我的应用程序中滚动视图内的模式。 如果我的数组列表中有5个“时间卡”对象,那么将有5个垂直堆叠的模态。

我想要的最终行为是,如果我有5张卡片的垂直堆叠,我想为第一张卡片设置动画效果,完成后启动第二张,完成之后再制作第三张,依此类推。

这是我的方法:

public void inflatetimeCardContainer(){
    timecardContainer.removeAllViews();
    int tclistIndex = 0;
    for(TimeCard tc : timeCardList){
        timeCardFragment = (RelativeLayout)LayoutInflater.from(this).inflate(R.layout.timecard_fragment, timecardContainer, false);
        textViewTitle = (TextView)timeCardFragment.findViewById(R.id.textViewTitle);
        textViewHours = (TextView)timeCardFragment.findViewById(R.id.textViewHours);
        textViewPay = (TextView)timeCardFragment.findViewById(R.id.textViewPay);
        textViewNotes = (TextView)timeCardFragment.findViewById(R.id.textViewNotes);
        buttonDelete = (Button)timeCardFragment.findViewById(R.id.buttonDelete);

        buttonDelete.setOnClickListener(handleButtonDelete);
        buttonDelete.setId(tclistIndex++);

        textViewTitle.setText(tc.getTitle());
        textViewHours.setText("Hours: " + String.valueOf(tc.getHours()));
        textViewPay.setText("Pay after taxes: " + String.valueOf((tc.getHours()*tc.getPayRate())*0.77));
        textViewNotes.setText(tc.getNotes());

        timeCardFragment.setAlpha(0);
        timecardContainer.addView(timeCardFragment);
        timeCardFragment.animate().alpha(1.0f);
        // SOME KIND OF PAUSE HERE UNTIL ANIMATION IS DONE
        // One the animation is done, continue in my for loop
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM