【问题标题】:Android: Set visibility of view on animationAndroid:设置动画视图的可见性
【发布时间】:2016-04-19 08:14:08
【问题描述】:

我正在开发一个具有自定义列表视图的应用程序。一项列表视图包含四个文本框。应用程序的需求就像当我点击一个文本框时,一个图像视图应该是可见的,放大然后缩小,缩小后可见性应该消失了。

我尝试的是:

在 getView 方法中的适配器中

if(clickPosition == position){  
    holder.imageViewOne.setVisibility(View.VISIBLE);
    holder.imageViewOne.startAnimation(zoominout);
    zoominout.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation arg0) {}

        @Override
        public void onAnimationRepeat(Animation arg0) {}

        @Override
        public void onAnimationEnd(Animation arg0) {
            holder.imageViewOne.setVisibility(View.GONE);
            clickedPosition = -1;
        }
    });
}

我的动画 XML

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

<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="3"
    android:toYScale="3" >
</scale>

<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5"
    android:startOffset="2000" >
</scale>

</set>

当我运行我的应用程序时,动画效果很好。

问题是:

1) 图像视图上的可见性不起作用。

2) 我的列表如下图所示:

当我单击列表项 1 时,第一个文本视图,动画正在工作,但是当我单击列表视图 2 时,第一个文本视图动画正在列表项 1 和列表项 2 上工作。

我该怎么办?我错过了什么吗?请指导我提出您的宝贵建议。

【问题讨论】:

  • 图像视图上的可见性不起作用。像图像保持或消失?实际上发生了什么?
  • 动画完成后图像停留在那里。我试过 notifyDataSetChanged();也。但不工作。

标签: android animation android-animation android-adapter


【解决方案1】:

您需要维护每个图像的状态数组,无论它是否可见。您必须在 getView() 方法中的每个 ImageView 上根据该状态数组应用可见性检查。现在,每次当 ImageView 的动画结束时,您都必须在状态数组中更新该图像的相应状态,然后调用 notifyDataSetChanged()

【讨论】:

    猜你喜欢
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多