我在VideoView中有一个TextView和一个Relative layout。我正在做的是,使TextView动画到屏幕的中心,更改文本并返回到屏幕的角落。我在屏幕中央放置了一个视频视图。当TextView设置动画时,它会落后于Video View破坏动画。我已经尽力找到任何解决方法以在视频视图之上显示TextView,但并不幸运。因此,我想知道有关此问题的任何帮助,或者可以在动画事件中将“视频视图”的可见性设置为false和true,这样我就可以实现所需的功能。

这是我的相对布局代码

  <RelativeLayout
    android:layout_width="1440dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="0dp"
    android:background="#000000" >
  <VideoView
    android:id="@+id/videoView1"
    android:layout_width="962dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    />
  <TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="970dp"
    android:layout_marginTop="320dp"
    android:paddingLeft="58dp"
    android:text="00"
    android:textAlignment="center"
    android:textSize="150sp"
    android:onClick="increaseCounter"
    android:clickable="true"
    android:textColor="#FF0000">
  <requestFocus
    android:duplicateParentState="true"
    android:focusable="true"
    android:focusableInTouchMode="true" />
  </TextView>
  </RelativeLayout>


我在textview上使用翻译动画,我想在Video View上设置动画。

最佳答案

查看以下布局:

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

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="This is a sample text message"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>


这是我尝试过的布局,下面是我使用过的动画

 @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            .......
            textView.startAnimation(inFromRightAnimation());
            textView.requestFocus();
        }
        private Animation inFromRightAnimation() {

            Animation inFromRight = new TranslateAnimation(
                    Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
            );
            inFromRight.setDuration(5*1000);
            inFromRight.setInterpolator(new AccelerateInterpolator());
            return inFromRight;
        }


并且它可以正常工作。 VideoView将位于TextView的后面,并且TextView在VideoView上方正确地从整个屏幕向右平移。

10-07 12:48
查看更多