我有一個帶重寫getView方法的listview來填充它。 現在,我想讓列表中的每個項目都動起來或從屏幕的右側 移動到項目通常應該出現的左側。如何爲每個列表視圖項目製作翻譯動畫
每個項目的動畫不應該在同一時間啓動,它必須延遲對於其他項目,移動前幾毫秒...
好,這是我的適配器類:
public class MyAdapter extends ArrayAdapter<String>{
private Context context;
private String[] info;
public MyAdapter(Context context, int resource,
String[] objects) {
super(context, resource, objects);
// TODO Auto-generated constructor stub
this.context = context;
this.info = objects;
}
protected class RowViewHolder {
public TextView text1;
public CheckBox cb;
public String ss;
}
@Override
public View getView(int pos, View inView, ViewGroup parent) {
View vix = inView;
RowViewHolder holder;
if (vix == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vix = inflater.inflate(R.layout.check_list, null);
}
holder = new RowViewHolder();
holder.text1 = (TextView) vix.findViewById(R.id.info_group);
holder.text1.setText(info[pos]);
holder.ss = info[pos];
holder.cb = (CheckBox) vix.findViewById(R.id.check);
holder.cb.setTag(holder.ss);
holder.cb.setOnCheckedChangeListener(CbListen);
vix.setTag(holder);
return vix;
}
private OnCheckedChangeListener CbListen = new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton com, boolean pool) {
// TODO Auto-generated method stub
String state = (com.getTag()).toString();
if(com.isChecked()){
System.out.println(state+" CHECKED");
}else{
System.out.println(state+" UNCHECKED");
}
}
};
}
任何想法? :)
UPDATE
嘛,肯定是! LOL:p
只是下載那些ApiDemos「像Farhan說的那樣」 ,你們會在包視圖中找到一些像LayoutAnimation2樣本。
那裏,列表中的每個項目都被動畫爲向下填充 翻譯動畫,而Alpha分別在變化。
這就是我對我的情況做:
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(500);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 50.0f,Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(1000);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
group_list.setLayoutAnimation(controller);
我把這個我下面的setAdapter()函數, 你們可以讓它看起來與加速,減速等效果更加舒適。
:p
noop不知道,但你可能想檢查api演示的源代碼....真的有一些關於動畫的好東西太.. – Farhan