【问题标题】:Animations no longer work when I hide a ProgressBar当我隐藏 ProgressBar 时动画不再起作用
【发布时间】:2011-05-23 20:44:05
【问题描述】:

长时间的听众,第一次来电......

我正在创建一个从名为 SplashBase 的 Activity 派生的初始屏幕,该屏幕位于共享项目中。布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/linlytSplash"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
>
   <ImageView
      android:id="@+id/imgvwSplash"
      android:src="@drawable/splashscreen"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
   ></ImageView>

   <LinearLayout
      android:id="@+id/linlytProgress"
      android:orientation="horizontal"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_gravity="center"
      android:gravity="center"
   >
      <ProgressBar
         android:id="@+id/progbarProgress"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginRight="5dp"
      ></ProgressBar>
      <TextView
         android:id="@+id/txtvwProgress"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dip"
         android:gravity="center_vertical"
         android:text="@string/loading_ellipsis"
         android:textStyle="bold"
      ></TextView>

   </LinearLayout>

</LinearLayout>

我正在加载这样的动画:

  Animation animation = AnimationUtils.loadAnimation(this, R.anim.splashscreen_anim);
  animation.setAnimationListener(new AnimationListener() {
     public void onAnimationEnd(Animation animation) {
        // Advance to the next screen.
        if (null != m_intentToLaunch) {
           startActivity(m_intentToLaunch);
        }

        finish();
     }
  });

  animation.setStartTime(AnimationUtils.currentAnimationTimeMillis() + 1000);

我的主项目中有一个名为 Splash 的派生类。

我已经有这个闪屏很长时间了,动画一直有效。我的 ImageView 显示 2 秒,然后在调用 finish() 并加载下一个 Activity 之前动画并消失。

我现在添加一个仅在第一秒显示的 ProgressBar(不完全是,但如果我这样解释会更清楚)。由于某种原因,在我隐藏 ProgressBar 后,动画不再适用于 ImageView。当我打电话时

findViewById(R.id.linlytProgress).setVisibility(View.INVISIBLE);

动画不再起作用。为了测试,我打了以下电话:

findViewById(R.id.txtvwProgress).setVisibility(View.INVISIBLE);

然后

findViewById(R.id.progbarProgress).setVisibility(View.INVISIBLE);

当我只隐藏 TextView 时,一切正常。当我隐藏 ProgressBar 时,繁荣,我的 ImageView 不再动画。我很茫然。

【问题讨论】:

  • 你的动画效果如何?它们是自定义动画吗?
  • 我已将该信息添加到问题中。
  • 动画在做什么?我们可以看看代码吗?
  • 当然,但那是另外 62 行代码。第一次来,你建议我怎么继续?只需将其添加到问题中,将其发布在评论中,pastebin?
  • 我不确定。 Pastebin 总是一个不错的选择。不确定看到它是否会有所帮助,但值得一看。到目前为止,您发布的内容中没有任何明显的内容。很奇怪:/

标签: android animation progress-bar


【解决方案1】:

对我来说听起来像是一个错误。创建一个重现错误的示例项目,并在http://b.android.com 上使用该示例项目提交错误。请务必提及您看到的错误(特定的硬件或仿真器版本)。如果您想到了,请在此答案中添加评论,并附上错误报告的链接。

【讨论】:

    【解决方案2】:

    我终于找到了自己问题的答案。该视图需要失效。

    findViewById(R.id.imgvwSplash).invalidate();
    

    瞧!它完全符合预期,到目前为止,在我尝试过的每个平台上都可以正常工作。

    感谢所有查看问题的人。

    -I_Artist

    【讨论】:

      猜你喜欢
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多