2013-03-26 74 views
1

我有一個TextView以及一個VideoViewRelative layout。我正在做的是,將TextView設置爲屏幕中心,改變文本並回到屏幕的角落。我有一個視頻視圖放置在屏幕的中心。當TextView生成動畫時,它會在視頻視圖背後破壞動畫。我努力尋找任何解決方法在視頻視圖頂部顯示TextView,但不幸運。所以我想知道關於這個問題的任何幫助,或者我可以將視頻視圖的可見性設置爲虛假和真實的動畫事件,所以我可以實現我想要的。Android視頻查看可見度

這裏是我的相對佈局代碼

<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的動畫,我想在動畫視頻觀看的頂部。

+0

你試過setvisibility方法 – Janmejoy 2013-03-26 06:59:46

+0

是的,我嘗試setVisibility(View.Invisible);和setVisibility(View.Visible);它確實隱藏了視頻視圖,但是可見的視圖執行並且視頻在巨大延遲後顯示 – 2013-03-26 07:05:18

回答

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

不,我嘗試了這個,但是從技術上來說它不會工作,因爲相對佈局在z-索引,TextView將始終隱藏在視頻視圖後面,因爲它首先被定義並且具有最低的Z-索引 – 2013-03-26 07:25:59

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上方正確轉換。

+0

這似乎是一個強有力的答案,我肯定會嘗試接受答案,如果它在我的結尾:)謝謝 – 2013-03-26 10:07:58

+0

你好,沒有運氣,你的代碼在我沒有分配任何視頻到videoView之前工作,但是一旦我設置了視頻的Uri(從http流入),動畫開始在視頻視圖的後面工作 – 2013-03-26 11:50:50