2015-07-13 71 views
1

我與Fade In AnimationListView列表視圖行淡入動畫

工作,但我面對的奇怪的錯誤動畫多次:

一些行再次動畫但是getView()不是召之即來。 。 這怎麼可能 ?

enter image description here

我的自定義適配器如下: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; 
    } 
} 

任何幫助是極大的appriciated ..

謝謝

回答

2

通過你的看法這方法

ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA,0,1); 
    animator.setDuration(1000); 
    animator.start(); 

希望這有助於您

+0

這是工作..謝謝你的幫助.. – Kushal

1

@Ram蒙達爾答案是絕對正確的..

但我也嘗試使用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 
     } 
    }); 

由於谷歌IO的ListView動畫視頻DevBytes:Video和感謝聊天哈斯先生分享精彩知識..