嗨我正在我的android應用程序中播放視頻,現在我想控制我的視頻播放全屏我有一個代碼,但它包含錯誤,它說,void是無效的變量類型onmeasure我不知道如何糾正錯誤覆蓋OnMeasure方法
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();
}
}
感謝
好,我把它拿走了斷的OnCreate並把它放在那的OnCreate之後,但在此仍收到錯誤新。 setlayoutparams ....我想我應該用我的佈局替換它.....這就是我做的,但它不能被解析爲變量, – user1794499 2013-03-09 03:50:48
@ user1794499請記住,'onMeasure()'是一個View方法。你在「活動」中工作。至於佈局參數的設置,因爲這個方法是用於View類的,所以它使用'this'。你想要的是引用你的視圖,我認爲你想要的是你的VideoView。只需將參考變爲實例變量即可。 – 2013-03-09 04:06:39
好了,但我的變量應該是什麼類型,int?對不起,打擾好友 – user1794499 2013-03-09 04:08:50