1

我有一个 TextView 和VideoView一个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 上使用翻译动画,我想在视频视图之上制作动画。

4

3 回答 3

1

看看下面的布局:

<?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 上方正确地从整个屏幕向右转换到中心。

于 2013-03-26T10:05:32.907 回答
0

尝试使用,它会出现在窗口顶部的文本

<RelativeLayout
 android:layout_width="1440dp"
 android:layout_height="wrap_content"
 android:background="#000000" >
<TextView
 android:id="@+id/textView2"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="00"
 android:textAlignment="center"
 android:layout_alignParentTop="true"
 android:textSize="150sp"
 android:onClick="increaseCounter"
 android:clickable="true"
 android:textColor="#FF0000">
 <requestFocus
 android:duplicateParentState="true"
 android:focusable="true"
 android:focusableInTouchMode="true" />
 </TextView>
 <VideoView
 android:id="@+id/videoView1"
 android:layout_below="@+id/textView2"
 android:layout_width="962dp"
 android:layout_height="wrap_content"
 />
 </RelativeLayout>
于 2013-03-26T07:21:44.247 回答
0

终于找到了解决我面临的问题的方法。创建了一个RelativeLayout具有最高z-index(定义在最底部)的控件,并放置了我想要在动画期间继续显示的所有控件,除了videoView我在动画期间实际想要隐藏的控件并textView在视频视图的顶部设置动画。在动画开始时,我将最终RelativeLayout背景设置为黑色,并在动画结束时将其重置为透明。一种黑客,但工作。

    @Override
    public void onAnimationStart(Animation arg0) {

       RelativeLayout rl =(RelativeLayout) findViewById(R.id.superView);
    rl.setBackgroundColor(Color.BLACK);
        }

    @Override
    public void onAnimationEnd(Animation arg0) {

    RelativeLayout rl =(RelativeLayout) findViewById(R.id.superView);
    rl.setBackgroundColor(Color.TRANSPARENT);
        }
于 2013-03-26T13:36:41.487 回答