2017-09-26 108 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

相关问题