我正在尝试制作一个应用程序,您可以根据陀螺仪/指南针的值控制视频的X位置。例如,视频的左侧仅在屏幕上显示,而与手机的运动一致,电影的其余部分在屏幕上显示。
我认为最简单的方法是创建一个比手机屏幕更大的视图,然后控制视频视图的 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>
我试图做到这一点并它的工作..唯一的区别是我使用了相对的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);
}
}
有两个按钮可以将视频向右或向下移动 100px
祝你好运