1.androidmainifest文件中配置
android:largeHeap="true"
2.model配置 compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
3.xml<com.google.vr.sdk.widgets.pano.VrPanoramaView android:id="@+id/vr" android:layout_width="match_parent" android:layout_height="match_parent"></com.google.vr.sdk.widgets.pano.VrPanoramaView>导入model common commonwidget panowidget
4.//初始化vr//设置左下角信息按钮隐藏vr.setInfoButtonEnabled(false);//隐藏右下角全屏显示按钮vr.setFullscreenButtonEnabled(false);//切换VR的模式 参数: VrWidgetView.DisplayMode.FULLSCREEN_STEREO设备模式(手机横着放试试) VrWidgetView.DisplayMode.FULLSCREEN_MONO手机模式 vr.setDisplayMode(VrPanoramaView.DisplayMode.FULLSCREEN_STEREO); //D.设置对VR运行状态的监听,如果VR运行出现错误,可以及时处了.vr.setEventListener(new MyListner());//设置立体显示 voidVoidBitmapAsyncTask = new AsyncTask<Void, Void, Bitmap>() { @Override protected Bitmap doInBackground(Void... voids) { try { InputStream open= getAssets().open("andes.jpg"); Bitmap bitmap= BitmapFactory.decodeStream(open); return bitmap; } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Bitmap bitmap) { VrPanoramaView.Options options= new VrPanoramaView.Options(); //设置立体显示 options.inputType= VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER; vr.loadImageFromBitmap(bitmap,options); super.onPostExecute(bitmap); } }; voidVoidBitmapAsyncTask.execute();5.与aciivity生命周期同步onpause supper前:mVrPanoramaView.pauseRendering();onresume supper后: mVrPanoramaView.resumeRendering();//关闭渲染视图 ondestory supper前://关闭渲染试图mVrPanoramaView.shutdown(); if(mImagerLoaderTask != null){ //在退出activity时,如果异步任务没有取消,就取消 if(!mImagerLoaderTask.isCancelled()){ mImagerLoaderTask.cancel(true); } }