Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 重写OnMeasure方法时出错_Android_Android Layout_Fullscreen_Android Videoview - Fatal编程技术网

Android 重写OnMeasure方法时出错

Android 重写OnMeasure方法时出错,android,android-layout,fullscreen,android-videoview,Android,Android Layout,Fullscreen,Android Videoview,嗨,我在用我的android应用程序播放视频,现在我想控制我的视频全屏播放。我有一个代码,但它包含错误。它说void不是有效的变量类型,我不知道如何更正 public class video extends Activity { String SrcPath = "rtsp://v8.cache3.c.youtube.com/CjYLENy73wIaLQltaP8vg4qMsBMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOL6qv2DoMPrUAw=/0/0/0/

嗨,我在用我的android应用程序播放视频,现在我想控制我的视频全屏播放。我有一个代码,但它包含错误。它说void不是有效的变量类型,我不知道如何更正

public class video extends Activity {


String SrcPath =  "rtsp://v8.cache3.c.youtube.com/CjYLENy73wIaLQltaP8vg4qMsBMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOL6qv2DoMPrUAw=/0/0/0/video.3gp";

/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video1);


protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec){
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   this.setMeasuredDimension(parentWidth/2, parentHeight);
   this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}


VideoView myVideoView = (VideoView)findViewById(R.id.vview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();

}
 }

谢谢

编译问题在于存在括号问题。移动

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec){
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   this.setMeasuredDimension(parentWidth/2, parentHeight);
   this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
因此它不在
onCreate()
中。现在,方法不能直接包含其他方法


此外,不是
活动
中的方法,而是
视图
中的方法。您应该查看文档,以便准确地了解您想要做什么。

似乎您可能希望将这两个函数作为类中的方法:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video1);

    // Set up the video when you create the activity
    VideoView myVideoView = (VideoView)findViewById(R.id.vview);
    myVideoView.setVideoURI(Uri.parse(SrcPath));
    myVideoView.setMediaController(new MediaController(this));
    myVideoView.requestFocus();
}

// On measure should be a different method also in the class video
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   this.setMeasuredDimension(parentWidth/2, parentHeight);
   this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

好的,我已经把它从oncreate上取下来,放在oncreate之后,但是仍然在这里得到new的错误。setlayoutparams…我想我应该用我的布局替换它…这就是我所做的,但它不能作为变量解析,@user1794499请记住,
onMeasure()
是一个视图方法。您正在进行
活动
。至于布局参数的设置,由于此方法用于视图类,因此它使用
this
。你想要的是引用你的观点,我想你想要的是你的视频观点。只需将引用设为实例变量,仅此而已。明白了,但我的变量应该是什么类型,int?对不起打扰了buddy@user1794499如果您试图引用
视频视图
,您的类型将是
视频视图
。你在说什么变量?我的意思是如果我按照你说的做…使用一个实例变量来引用我的布局让我们称这个变量为new,因为它已经在里面了。setlayoutparams…我想我应该给它布局,因为它是类型而不是videoview,因为我需要引用布局,而不仅仅是在视图中。你能用new确认我吗参数位于.setlayoutparams。。它应该是我的xml文件名吗?我不确定,但您可以通过查看xml来找到它。video1.xml中的顶级视图很可能被称为___;布局。例如:它可能是LinearLayout,在这种情况下,我认为它会使参数
成为新的LinearLayout.LayoutParams(parentWidth/2,parentHeight)