首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重写OnMeasure方法时出错

重写OnMeasure方法时出错
EN

Stack Overflow用户
提问于 2013-03-09 11:26:40
回答 2查看 2.2K关注 0票数 0

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

代码语言:javascript
复制
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();

}
 }

谢谢

EN

回答 2

Stack Overflow用户

发布于 2013-03-09 11:32:31

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

代码语言:javascript
复制
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()中。现在,方法不能直接包含其他方法。

此外,onMeasure()不是Activity中的方法,而是View中的方法。您应该查看文档,以便准确地确定您想要做什么。

票数 0
EN

Stack Overflow用户

发布于 2013-03-09 11:42:15

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

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15306788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档