为什么一个视图后,没有setVisibility工作是动画?视图、动画、工作、setVisibility

2023-09-12 11:27:44 作者:千诺

为什么不TextView的成为无形?

下面是我的布局XML:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

    <的TextView
    机器人:ID =@ + ID / tvRotate
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=旋转我
/>
< / LinearLayout中>
 

..这里是我的活动:

 公共类RotateMeActivity扩展活动
{
    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        TextView的tvRotate =(TextView中)findViewById(R.id.tvRotate);

        RotateAnimation R =新RotateAnimation(0,180,Animation.RELATIVE_TO_SELF,0.5F,Animation.RELATIVE_TO_SELF,0.5F);
        r.setDuration(0);
        r.setFillAfter(真正的);
        tvRotate.startAnimation(r)的;
        tvRotate.setVisibility(View.INVISIBLE);
    }
}
 
用PPT如何制作叠影字 王图科技

我的目标是旋转视图,然后能够隐藏并通过设置setVisibility它显示在code。下面的工作,但setRotation仅在API级别11.我需要一种方法来做到这一点在API级别10。

  tvRotate.setRotation(180); //而非RotateAnimation,仅适用于API级别11
tvRotate.setVisibility(View.INVISIBLE);
 

解决方案

有关我叫 clearAnimation 视图的解决了这一问题。在我来说,我希望做一个翻译后的视图设置回原来的位置与fillAfter设置为true。

Why doesn't the textView become invisible?

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>

..and here is my 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);
    }
}

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

解决方案

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.