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.
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);
And then while adding items through button onClick
l.startLayoutAnimation();
Any other suggestions to achieve such animation.
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
Android ListView is a ViewGroup that is used to display the list of items in multiple rows and contains an adapter that automatically inserts the items into the list. The main purpose of the adapter is to fetch data from an array or database and insert each item that placed into the list for the desired result.
A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With