gpt4 book ai didi

java - 如何为每个 ListView 项目制作翻译动画

转载 作者:IT老高 更新时间:2023-10-28 21:09:10 30 4
gpt4 key购买 nike

我有一个带有覆盖 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");
}
}
};

}

有什么想法吗? :)

更新

嗯,肯定是的!大声笑:p

只需下载那些“像 Farhan 所说的那样”的 ApiDemos你们会在包 View 中找到类似 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

最佳答案

@user724861给出了完美的答案!!我怎么发现将他建议的代码放在哪里令人困惑...我将该代码放在我的 ListFragment Activity 中,如下所示..

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

关于java - 如何为每个 ListView 项目制作翻译动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6853918/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com