为什么在视图动画后 setVisibility 不起作用? [英] Why doesn't setVisibility work after a view is animated?

查看:22
本文介绍了为什么在视图动画后 setVisibility 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 textView 不可见?

Why doesn't the textView become invisible?

这是我的布局 xml:

Here is my layout 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>

..这是我的活动:

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

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

My goal is to rotate a view and then be able to hide and show it in code by setting setVisibility. The following works, but setRotation is available only in API Level 11. I need a way to do it in API Level 10.

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

推荐答案

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

For me calling clearAnimation of the View fixed the problem. In my case I wanted to set the View back to its original position after doing a translation with fillAfter set to true.

这篇关于为什么在视图动画后 setVisibility 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆