【问题标题】:Android Controling Video PositionAndroid 控制视频位置
【发布时间】:2013-09-09 09:17:38
【问题描述】:

我正在尝试制作一个应用程序,您可以根据 Gyro/Compass 的值控制视频的 X 位置。比如视频的左侧只出现在屏幕上,其余的电影根据手机的移动出现在屏幕上。

我认为最简单的方法是创建一个比手机屏幕大的 View,然后控制 videoView 的 X 值,或者类似的东西。

有人知道怎么做吗? 我应该为此使用 VideoView 吗? 什么是最好的布局?

我认为我尝试了所有方法,但无法成功。

我将在此处发布我的一项尝试,以帮助了解我正在尝试做什么。

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/absoluteLayout"
    android:layout_width="3000dp"
    android:layout_height="3000dp"
    android:layout_x="-500dp" >

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="2000dp"
        android:layout_height="1255dp"
        android:layout_x="-279dp" />

</AbsoluteLayout>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    我试着做它和它的工作..唯一的区别我使用了相对的layoyt..检查这个代码:

    布局:

    <RelativeLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="2000px"
        android:layout_height="1125px"
    
        tools:context=".MainActivity" >
    
    
        <VideoView
            android:id="@+id/videoView"
            android:layout_width="2000px"
            android:layout_height="1125px"
            android:layout_marginTop="0px"
            android:layout_marginLeft="0px" />
    
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="right"
            android:onClick="goright"
            />
    
        <Button 
            android:layout_width="wrap_content"
            android:layout_marginLeft="100px"
            android:layout_height="wrap_content"
            android:text="down"
            android:onClick="godown"
            />
    
    
    </RelativeLayout>
    

    代码是:

      public class MainActivity extends Activity {
            private VideoView vv;
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
    
                vv = (VideoView) findViewById(R.id.videoView);
    
                vv.setVideoPath("sdcard/foo/foo.mp4");
                vv.start();
    
            }
    
            public void goright(View v) {
                RelativeLayout.LayoutParams ll = (RelativeLayout.LayoutParams) vv
                        .getLayoutParams();
                ll.setMargins(ll.leftMargin - 100, ll.topMargin, ll.rightMargin,
                        ll.bottomMargin);
                vv.setLayoutParams(ll);
            }
    
            public void godown(View v) {
                RelativeLayout.LayoutParams ll = (RelativeLayout.LayoutParams) vv
                        .getLayoutParams();
                ll.setMargins(ll.leftMargin, ll.topMargin - 100, ll.rightMargin,
                        ll.bottomMargin);
                vv.setLayoutParams(ll);
    
            }
    
        }
    

    有两个按钮可以将视频向右或向下移动 100 像素

    祝你好运,

    【讨论】:

    • 我测试过它并没有移动视频.. 看起来它正在裁剪电影而不移动它。对你也一样吗?我正在使用不同的布局进行测试,我总是遇到这个问题,视频不会从屏幕上移开,而是被裁剪了。
    • 我想你会在这里找到答案:stackoverflow.com/a/2216788/2267723 .. 更多信息:stackoverflow.com/a/7200749/2267723
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多