java – 如何使每个listview项目的翻译动画

我有一个列表视图与覆盖getView方法来填充它。
现在,我想让列表的每个项目动画或从右侧移动
屏幕的左侧应显示项目。

每个项目的动画不应该同时开始,它必须延迟几毫秒之前其他项目移动…

好了,这是我的适配器类:

public class MyAdapter extends ArrayAdapter<String>{

    private Context context;
    private String[] info;

    public MyAdapter(Context context, int resource,
            String[] objects) {
        super(context, resource, objects);
        // TODO Auto-generated constructor stub
        this.context = context;
        this.info = objects;

    }

    protected class RowViewHolder {
        public TextView text1;
        public CheckBox cb;
        public String ss;
    }

    @Override
    public View getView(int pos, View inView, ViewGroup parent) {
           View vix = inView;

           RowViewHolder holder;

           if (vix == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                vix = inflater.inflate(R.layout.check_list, null);
           }    
                holder = new RowViewHolder();

                holder.text1 = (TextView) vix.findViewById(R.id.info_group);
                holder.text1.setText(info[pos]);

                holder.ss = info[pos];

                holder.cb = (CheckBox) vix.findViewById(R.id.check);
                holder.cb.setTag(holder.ss);
                holder.cb.setOnCheckedChangeListener(CbListen);

                vix.setTag(holder);

           return vix;
    }

    private OnCheckedChangeListener CbListen = new OnCheckedChangeListener(){
        @Override
        public void onCheckedChanged(CompoundButton com, boolean pool) {
            // TODO Auto-generated method stub
            String state = (com.getTag()).toString();

            if(com.isChecked()){
                System.out.println(state+" CHECKED");
            }else{
                System.out.println(state+" UNCHECKED");
            }
        }
    };

}

任何想法? 🙂

更新

嗯,当然是! LOL:p

只是下载那些ApiDemos“像Farhan说的”
你们会在包视图中找到一些像LayoutAnimation2样例。

在那里,列表的每个项目都被动画化以向下填充
翻译动画,而alpha分别改变。

这里是我为我的情况:

AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(500);
    set.addAnimation(animation);

    animation = new TranslateAnimation(
        Animation.RELATIVE_TO_SELF, 50.0f,Animation.RELATIVE_TO_SELF, 0.0f,
        Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f
    );
    animation.setDuration(1000);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);

    group_list.setLayoutAnimation(controller);

我把这下面我的setAdapter()函数,
你们可以让它看起来更舒适与加速减速等效果。

:p

@ user724861给了完美的答案!
我发现它是混乱在哪里放他的代码他建议…我把这些代码在我的ListFragment活动如下..

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);        

    AnimationSet set = new AnimationSet(true);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(300);
    set.addAnimation(animation);

    /*animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 50.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(10);
    set.addAnimation(animation); just comment if you don't want :) */ 
    LayoutAnimationController controller = new LayoutAnimationController(
            set, 0.5f);

    lv.setLayoutAnimation(controller);

    adapter = new LazyAdapter(getActivity(), numResults, nodes, tabType);
    setListAdapter(adapter);
}
http://stackoverflow.com/questions/6853918/how-to-make-translation-animation-for-each-listview-items

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:java – 如何使每个listview项目的翻译动画