当我隐藏进度条时,动画不再起作用

发布于 2024-11-08 21:45:43 字数 2598 浏览 4 评论 0原文

长时间的听众,第一次调用者...

我正在创建一个从名为 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 后,动画不再在 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 不再有动画。我不知所措。

long time listener, first time caller...

I am creating a splash screen derived from Activity called SplashBase that is placed inside a shared project. The layout is the following:

<?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>

I am loading the animations like this :

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

I have a derived class called Splash which lives in my main project.

I've had this splash screen for a long time now, the animation has always worked. My ImageView is shown for 2 seconds, and then animates and disappears before calling finish() and loading the next Activity.

I am now adding a ProgressBar which only be shown for the first second (not exactly, but it's clearer if I explain it that way). For some reason, after I hide the ProgressBar, the animation no longer works on the ImageView. When I call

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

the animation no longer works. In order to test I have placed the following calls:

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

and then

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

When I hide only the TextView, things work as expected. When I hide the ProgressBar, boom, my ImageView no longer animates. I'm at a loss.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妄想挽回 2024-11-15 21:45:43

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

Sounds like a bug to me. Create a sample project that reproduces the error and file a bug with that sample project on http://b.android.com. Be sure to mention on the bug where you're seeing this (particular hardware or emulator version). If you think of it, add a comment to this answer with a link to the bug report.

老旧海报 2024-11-15 21:45:43

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

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

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

感谢所有看过这个问题的人。

-I_艺术家

I finally found the answer to my own question. The view needed to be invalidated.

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

et voila! It works exactly as expected, and so far on every platform that I tried it on.

Thanks to everyone who took a look at the question.

-I_Artist

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文