为什么 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/