Android 用于在ListView中打开或关闭视图的动画,只有一个动画工作

Android 用于在ListView中打开或关闭视图的动画,只有一个动画工作,android,listview,animation,onclicklistener,Android,Listview,Animation,Onclicklistener,我有一个列表视图,表示一周中的7天。每行都有一个标题和内容 我已经设置了单击行标题的动画。单击时,该行的内容将向上/向下滑动 目前只有用于向下滑动打开内容的动画工作,无法理解为什么向上滑动动画不工作?!&^@ ListView适配器的getView 向下滑动动画 向上滑动动画 是否在调用动画后直接将view设置为view.GONE?看起来你的动画没有任何设定的时间,所以我想它会很快进入下一行代码。@RedRumming不幸的是,这并没有修复它。谢谢你的意见! @Override public V

我有一个列表视图,表示一周中的7天。每行都有一个标题和内容

我已经设置了单击行标题的动画。单击时,该行的内容将向上/向下滑动

目前只有用于向下滑动打开内容的动画工作,无法理解为什么向上滑动动画不工作?!&^@

ListView适配器的getView

向下滑动动画

向上滑动动画


是否在调用动画后直接将view设置为view.GONE?看起来你的动画没有任何设定的时间,所以我想它会很快进入下一行代码。@RedRumming不幸的是,这并没有修复它。谢谢你的意见!
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;

    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.row_schedule, null);
        holder.header = (LinearLayout) convertView.findViewById(R.id.header);
        holder.day = (CustomFontBoldTextView) convertView.findViewById(R.id.day);
        holder.isActive = (CustomFontBoldTextView) convertView.findViewById(R.id.is_active);
        holder.container = (LinearLayout) convertView.findViewById(R.id.container);
        holder.rangeBar = (RangeBar) convertView.findViewById(R.id.rangebar);
        holder.tvStartTime = (CustomFontBoldTextView) convertView.findViewById(R.id.start_time);
        holder.tvEndTime = (CustomFontBoldTextView) convertView.findViewById(R.id.end_time);
        convertView.setTag(holder);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.day.setText(schedules.get(position).getDay());

    if (schedules.get(position).getIsActive()) {
        holder.isActive.setText(R.string.btn_on);
        holder.isActive.setBackgroundResource(R.drawable.bg_green_rounded);
        holder.container.setVisibility(View.VISIBLE);
    }
    else {
        holder.isActive.setText(R.string.btn_off);
        holder.isActive.setBackgroundResource(R.drawable.bg_gray_rounded);
        holder.container.setVisibility(View.GONE);
    }

    holder.header.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (schedules.get(position).getIsActive()) {
                schedules.get(position).setIsActive(false);
                holder.container.setAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_up));
                holder.container.setVisibility(View.GONE);
                holder.isActive.setText(R.string.btn_off);
                holder.isActive.setBackgroundResource(R.drawable.bg_gray_rounded);
            }
            else {
                schedules.get(position).setIsActive(true);
                holder.container.setAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_down));
                holder.container.setVisibility(View.VISIBLE);
                holder.isActive.setText(R.string.btn_on);
                holder.isActive.setBackgroundResource(R.drawable.bg_green_rounded);
            }
        }
    });

    return convertView;
}
<?xml version="1.0" encoding="utf-8"?>
<set 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

<scale
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="250"
    android:fromXScale="1.0"
    android:toXScale="1.0"
    android:fromYScale="0.0"
    android:toYScale="1.0" />
<?xml version="1.0" encoding="utf-8"?>
<set 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

<scale
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="250"
    android:fromXScale="1.0"
    android:toXScale="1.0"
    android:fromYScale="1.0"
    android:toYScale="0.0" />