2017-09-26 35 views
0

我正在一個應用程序中比較視頻,我有這個用例。這是它看起來如何Two Videos view如何把兩個視頻並排隱藏其寬度的一半?

我一直在嘗試用自定義視圖來擴展相對佈局,並將視頻視圖放入其中,但我無法實現此結果。

您必須考慮到視頻寬度必須等於屏幕寬度,因爲當有人點擊某些視頻時,必須翻譯它,直到它完全可見爲止。我認爲應該將左側視頻轉換爲左側寬度屏幕的一半,並將相同的邏輯應用於右側視頻。

+0

請張貼一些代碼。 – iMDroid

+0

也是你得到的結果的細節。 – iMDroid

+0

使用權重和。 –

回答

0

我把一個樣品,你可以嘗試這個,裏面的的LinearLayout你可以把它用烏爾播放視頻

activty_main.xml

<?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"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@color/colorAccent"> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@color/colorPrimaryDark"> 

     </LinearLayout> 

    </LinearLayout> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:src="@mipmap/ic_launcher" /> 


</RelativeLayout> 

enter image description here

videoview
0

最簡單的方法是創建景觀線性佈局並放入裏面兩個視圖(SurfaceView或TextureView或GlSurfaceView)。並給這些意見的權重等於1。這將是這樣的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:baselineAligned="false" 
android:orientation="horizontal" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1" 
    android:layout_marginRight="8dp" > 

    <TextureView 
     android:id="@+id/double1_texture_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1" > 

    <TextureView 
     android:id="@+id/double2_texture_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

最好的樣本,看看是Grafika。 但是,如果你想比較視頻,那麼不要忘記其中一個視頻應該被裁剪,例如。因爲您需要將一個視頻的左側與另一個視頻的左側進行比較。不要忘記寬高比。

+0

但在這種情況下,當有人點擊它時,你如何處理視頻的翻譯? –

+0

只有正確的佈局才能達到這一目標。要進行翻譯和裁剪,您應該使用GL命令和GlSurfaceView。 – Sheikh

+0

我可以使用Object Animator實現動畫。在這裏你可以閱讀更多關於這個:https://developer.android.com/guide/topics/graphics/prop-animation.html#views –

0

我可以把它這樣做有以下佈局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<com.google.android.exoplayer2.ui.SimpleExoPlayerView 
    android:id="@+id/right_video" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/colorAccent" /> 

<com.google.android.exoplayer2.ui.SimpleExoPlayerView 
    android:id="@+id/left_video" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary" /> 

</FrameLayout> 

編程,在我的屏幕的寬度要求活動的onCreate,並在X軸平移。這看起來像:

Point screenDimens = ViewUtils.getScreenDimensions(this); 
    int videoSize = screenDimens.x; 
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) leftVideo.getLayoutParams(); 
    params.width = videoSize; 
    params.height = videoSize; 
    leftVideo.setLayoutParams(params); 
    rigthVideo.setLayoutParams(params); 
    leftVideo.setTranslationX(-videoSize/2); 
    rigthVideo.setTranslationX(videoSize/2); 

這是它的外觀:

enter image description here

相關問題