我正在使用Fade In Animation
ListView
但我面临着一个奇怪的错误:
有些行再次动画,但没有为它们调用getView()..这怎么可能?
我的自定义适配器如下: MyAdapter.java
public class MyAdapter extends ArrayAdapter<String> {
private Context mContext;
private Animation mAnim;
private String[] mData;
private ListView mList;
public MyAdapter(Context context, int resource, String[] objects, ListView mList) {
super(context, resource, objects);
this.mContext = context;
mAnim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
this.mData = objects;
this.mList = mList;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
ViewHolder mHolder;
if (convertView == null) {
mHolder = new ViewHolder();
} else {
mHolder = (ViewHolder) convertView.getTag();
}
view.setTag(mHolder);
mHolder.mTextview = (TextView) view.findViewById(android.R.id.text1);
mHolder.mTextview.setText(mData[position]);
if (mList.getFirstVisiblePosition() < position && position <= (mList.getFirstVisiblePosition() + mList.getChildCount())) {
Log.w("list", "scroll down..");
view.startAnimation(mAnim);
} else if (position < mList.getFirstVisiblePosition()) {
Log.w("list", "scroll up..");
view.startAnimation(mAnim);
}
return view;
}
static class ViewHolder {
private TextView mTextview;
}
}
任何帮助都非常适合..
谢谢
答案 0 :(得分:2)
尝试这样做。
ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA,0,1);
animator.setDuration(1000);
animator.start();
希望这有助于你
答案 1 :(得分:1)
@Ram Mondal答案绝对正确..
但我也试过使用ViewPropertyAnimation
并且它有效:
view.setAlpha(0); // Initially setting alpha to 0.0 value
ViewHolder mHolder;
if (convertView == null) {
mHolder = new ViewHolder();
} else {
mHolder = (ViewHolder) convertView.getTag();
}
view.setTag(mHolder);
mHolder.mTextview = (TextView) view.findViewById(android.R.id.text1);
mHolder.mTextview.setText(mData[position]);
// this was trick : this worked very correctly
view.animate().setDuration(500).alpha(1).withEndAction(new Runnable() {
@Override
public void run() {
// any work to do after animation completed
}
});
感谢Google IO ListView动画视频DevBytes:Video并感谢Chat Hasse先生分享精彩的知识..