Joh*_*ohn 5 animation android listview android-arrayadapter
我的目标是动画某些ListView项目,而不必担心getView通过在自定义中用新增加的列表项替换列表项来搞乱动画ArrayAdapter.
如果我使用convertView以避免使新项目膨胀,则动画的顺序会随机变化.
手动缓存视图工作正常,但我怀疑这是一个很好的解决方案.好主意?
我所做的就是在convertview 上设置动画,然后在每个convertview 上停止动画。这样,如果 ConvertView 是新的,则动画将停止然后播放,如果在结束前未回收,则继续播放直到结束。
编辑我似乎找不到示例,因此它将部分是伪代码。
在您的适配器中,您将看到如下内容:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView == null) {
// setup holder
holder = new ViewHolder();
LayoutInflater Inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = Inflater.inflate(mResourceId, null);
holder.image = (ImageView) convertView.findViewById(R.id.row_image);
holder.headline = (TextView) convertView.findViewById(R.id.row_headline);
convertView.setTag(holder);
} else {
// get existing row view
holder = (ViewHolder) convertView.getTag();
}
// GetView is only called on new items
// so now we stop the previous animation and start a new
holder.animation.stop(); // First you stop the animation
holder.animation = new animation(); // then you create new
holder.animation.start(); // then you start the animation.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1710 次 |
| 最近记录: |