android如何实现Listview的每一项按顺序水平移动到其显示位置的动画

本文介绍了如何使用Android的AnimationSet和LayoutAnimationController实现ListView中每一项元素从屏幕右边滑动到左边的效果,包括代码实现和具体步骤。
当开始显示listview的时候,让每一项按顺序从屏幕右边滑倒左边。
adapter代码如下

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");
}
}
};

}


试下这段代码:
`

  
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);

转载于:https://my.oschina.net/limbusnet/blog/76977

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值