给ListView的数据展示 做点动画效果,数据较多时,手指往上拉动数据时,下面的数据感觉是往上推的,直接上关键代码:
---------------------动画文件res/anim:---------------------------------
up_from_bottom.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="100%" android:toYDelta="0%"
android:duration="300" />
</set>
down_from_top.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="-100%" android:toYDelta="0%"
android:duration="300" />
</set>
------------在ListView的Adapter中使用------------
public class MyAnimAdapter extends BaseAdapter {
private int lastPosition = -1;
.........................
public BeforeRecordAdapter(Context context) {
super(context);
}
............................
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (null == convertView) {
viewHolder = new ViewHolder();
convertView = mInflater.inflate(R.layout.item_my_anim, null);
viewHolder.winnerTv = (TextView) convertView.findViewById(R.id.period_record_winner_name_tv);
viewHolder.ipTv = (TextView) convertView.findViewById(R.id.period_record_ip_tv);
viewHolder.userIdTv = (TextView) convertView.findViewById(R.id.period_record_winner_id_tv);
convertView.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder) convertView.getTag();
}
setBeforeItemData(viewHolder, position);
.................//设置数据
if (position > lastPosition) {//这里就是动画的应用
Animation animation = AnimationUtils.loadAnimation(mContext, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
convertView.startAnimation(animation);
lastPosition = position;
}
return convertView;
}
private static class ViewHolder {
private TextView winnerTv;
private TextView ipTv;
private TextView userIdTv;
public int rp;
}
}