android - 为什么在 View 动画后 setVisibility 不起作用?

标签 android animation rotation visibility rotateanimation

为什么 textView 不可见?

这是我的布局 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
    android:id="@+id/tvRotate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rotate Me"
/>
</LinearLayout>

..这是我的 Activity :

public class RotateMeActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tvRotate = (TextView) findViewById(R.id.tvRotate);

        RotateAnimation r = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        r.setDuration(0);
        r.setFillAfter(true);
        tvRotate.startAnimation(r);
        tvRotate.setVisibility(View.INVISIBLE);
    }
}

我的目标是旋转 View ,然后通过设置 setVisibility 在代码中隐藏和显示它。以下方法有效,但 setRotation 仅在 API 级别 11 中可用。我需要一种方法在 API 级别 10 中执行此操作。

tvRotate.setRotation(180);//instead of the RotateAnimation, only works in API Level 11
tvRotate.setVisibility(View.INVISIBLE);

最佳答案

对我来说,调用 View 的 clearAnimation 解决了这个问题。就我而言,我想在将 fillAfter 设置为 true 进行翻译后将 View 设置回其原始位置。

关于android - 为什么在 View 动画后 setVisibility 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8690029/

相关文章:

android - 如何使用 ActionBar Sherlock 设置选项卡样式

ios - 简单的ios动画: rotate window and reverse

jquery - 旋转图像、div 或列表元素的最佳方式

java - Android Studio 4.1 调试器断点不起作用

java - 使用循环计算多个字符串值的总和

css - css3中的拟合元素

delphi - 使用 GDI+ 旋转的图形看起来比原始图形大

android - 每当设备旋转时,使用 libgdx 的应用程序都会重新启动

android - 应用程序创建的线程如何被视为与应用程序的 ContentProvider 不同的应用程序?

HTML/CSS : How to stop the cursor after the last letter in this animated text?