本文介绍了在Android中的ListView滚动上设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为ListView
设置动画,以供用户滚动ListView
时使用.加载时我正在为ListView
设置动画,但是我想为滚动设置动画.
I want to set an animation for a ListView
for when a user scrolls the ListView
. I am setting an animation for ListView
when loading, but I want to set an animation for scrolling.
这是我在eclipse中的动画文件:
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;
}
这是一个将动画设置为列表视图的ActivityMain
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??
推荐答案
ListView适配器:
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);
}
动画:
<?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>
这篇关于在Android中的ListView滚动上设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!