use*_*861 29 java animation android listview translation
我有一个listview与覆盖getView方法来填充它.现在,我想让列表中的每个项目动画或从屏幕右侧移动到项目正常出现的左侧.
每个项目的动画不应该同时开始,它必须在其他项目移动之前延迟几毫秒...
好吧,这是我的适配器类:
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");
}
}
};
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?:)
UPDATE
嗯,肯定是!哈哈: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);
Run Code Online (Sandbox Code Playgroud)
我把它放在我的setAdapter()函数下面,你们可以通过加速 - 减速等效果让它变得更加舒适.
:p
@ user724861给出了完美答案!我怎么发现它把他建议的代码放在哪里令人困惑...我把这些代码放在我的ListFragment活动中,如下所示..
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(300);
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(10);
set.addAnimation(animation); just comment if you don't want :) */
LayoutAnimationController controller = new LayoutAnimationController(
set, 0.5f);
lv.setLayoutAnimation(controller);
adapter = new LazyAdapter(getActivity(), numResults, nodes, tabType);
setListAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14586 次 |
| 最近记录: |