set animation on listview scrolling in android
11,442
ListView Adapter:
Animation scaleUp;
public MyAdapter(...) {
//...
scaleUp = AnimationUtils.loadAnimation(activity, R.anim.scale_up_fast);
}
public View getView(final int position, View convertView, ViewGroup parent) {
CardView cv;
if (convertView == null){
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.your_layout, parent, false);
}
cv = (CardView) convertView.findById(R.id.yourView);//Change this to your view
cv.startAnimation(scaleUp);
}
Animation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="300"
android:fromXScale="0"
android:fromYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
</set>
Author by
Saeed Parand
Updated on June 04, 2022Comments
-
Saeed Parand almost 2 years
I want to set an animation for a
ListView
for when a user scrolls theListView
. I am setting an animation forListView
when loading, but I want to set an animation for scrolling.This is my animation file in eclipse :
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="schemas.android.com/apk/res/android"; android:duration="900" android:fromXDelta="-100%p" android:interpolator="@android:anim/linear_interpolator" android:repeatCount="0" android:repeatMode="reverse" android:fillEnabled="true" android:fillAfter="true" android:toXDelta="0%p" > </translate>
this code is set items to my listview :
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; StructNote item = getItem(position); if (convertView == null) { convertView = G.inflater.inflate(R.layout.adapter_notes, parent, false); holder = new ViewHolder(convertView); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.fill(this, item, position); return convertView; }
and this is a ActivityMain that set animation to listview
ListView lstContent = (ListView) findViewById(R.id.lstContent); Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate); lstContent.setLayoutAnimation(new LayoutAnimationController(animation));
Any one can help me??
-
Saeed Parand about 8 yearsDear friend , what is your suggestion between lots of wat ?
-
Ajay Pandya about 8 yearsLots of way to doing animation in different way as like scale view or parallex background just check on github
-
VVB over 7 yearsNice one, but how avoid animation for previously loaded items? I mean while scrolling down, providing animation to list item is OK but it shouldn't animate if I scroll up because those items are already loaded.