添加动画列表视图中的Andr​​oid视图、动画、列表、oid

2023-09-06 01:25:16 作者:莫名的被吸引。眼眸扦着妳

我要动画列表视图中的项目。在present我申请的过渡动画每次上添加新项目列表中的项目。但是,这不是我想要实现的动画效果。我想,当一个新的项目,在那个时候加入列表查看所有列表视图中移动的地方下来让位给新添加的项目。

I want to animate the items of the list view. At Present i am applying the Transition Animation on the list items whenever new items are added. But this is not the animation i want to achieve. I want that when a new item is added in the list view at that time the whole List view move a place down to make way for the newly added item.

目前的code我现在用的就是:

Currently the code i am using is :

set = new AnimationSet(true);

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

    animation = new TranslateAnimation(
        Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
        Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
    );
    animation.setDuration(150);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 1.0f);
    l.setLayoutAnimation(controller);
    l.setAdapter(listAdaptor);

然后一边通过按钮的onClick添加项目

And then while adding items through button onClick

    l.startLayoutAnimation();

任何其他建议来实现这样的动画。

Any other suggestions to achieve such animation.

推荐答案

我解决这个。我每个动画元素加在我的自定义适配器的getView方法。

I got the Solution to this. I animate each added element in the getView method of my Custom Adapter.

public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;

        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.simple_list_item_1, null);
        }

        ListData o = list.get(position);
        TextView tt = (TextView) v.findViewById(R.id.toptext);

        tt.setText(o.content);

        Log.d("ListTest", "Position : "+position);
       if(flag == false) {
        Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_top_to_bottom);
        v.startAnimation(animation);}
        return v;
    }

,从而实现了动画,因为我曾指出的。

And thereby achieved the animation as i had stated for.

 
精彩推荐
图片推荐