赞
踩
xml:
- <?xml version="1.0" encoding="utf-8"?>
- <layout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools">
- <data>
-
- </data>
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".activity.PanoramaActivity">
-
- <com.google.vr.sdk.widgets.pano.VrPanoramaView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/supermarket_vr" />
-
- </RelativeLayout>
- </layout>
java:
- package com.example.supermarket.activity;
-
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.util.Log;
- import com.alibaba.android.arouter.facade.annotation.Route;
- import com.example.common.util.CCRouterTable;
- import com.example.http.base.BaseViewJavaModel;
- import com.example.supermarket.R;
- import com.example.supermarket.databinding.ActivityPanoramaBinding;
- import com.example.view.base.BaseJavaActivity;
- import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener;
- import com.google.vr.sdk.widgets.pano.VrPanoramaView;
- import com.gyf.immersionbar.BarHide;
- import com.gyf.immersionbar.ImmersionBar;
-
- import java.io.IOException;
- import java.io.InputStream;
-
- @Route(path = CCRouterTable.SUPERMARKET_HOTEL_PANORAMA)
- public class PanoramaActivity extends BaseJavaActivity<ActivityPanoramaBinding, BaseViewJavaModel> {
-
- @Override
- protected void initListener() {
-
- }
-
- @Override
- protected BaseViewJavaModel initViewModel() {
- return null;
- }
-
- @Override
- protected boolean isARouterInject() {
- return false;
- }
-
- @Override
- protected boolean useEventBus() {
- return false;
- }
-
- @Override
- public int getLayoutId() {
- return R.layout.activity_panorama;
- }
-
- @Override
- public void initData() {
- // 设置沉浸式状态栏 transparent:#00000000----完全透明
- //ImmersionBar.with(this)
- // .hideBar(BarHide.FLAG_HIDE_STATUS_BAR)
- // .fitsSystemWindows(false).init();
- // 加载全景图片
- load360Image();
- }
-
- /**
- * 加载全景图片
- */
- private void load360Image() {
- /**获取assets文件夹下的图片**/
- InputStream open = null;
- try {
- open = getAssets().open("pic.jpg");
- } catch (IOException e) {
- e.printStackTrace();
- }
- Bitmap bitmap = BitmapFactory.decodeStream(open);
- /**设置加载VR图片的相关设置**/
- VrPanoramaView.Options options = new VrPanoramaView.Options();
- // VR显示模式
- options.inputType = VrPanoramaView.Options.TYPE_MONO;
- binding.supermarketVr.setStereoModeButtonEnabled(false);//隐藏VR眼镜按钮
- binding.supermarketVr.setInfoButtonEnabled(false);//隐藏信息按钮
- // binding.supermarketVr.setFullscreenButtonEnabled(false);//隐藏全屏按钮
- /**设置加载VR图片监听**/
- binding.supermarketVr.setEventListener(new VrPanoramaEventListener() {
- /**
- * 显示模式改变回调
- * 1.默认
- * 2.全屏模式
- * 3.VR观看模式,即横屏分屏模式
- * @param newDisplayMode 模式
- */
- @Override
- public void onDisplayModeChanged(int newDisplayMode) {
- super.onDisplayModeChanged(newDisplayMode);
- }
-
- /**
- * 加载VR图片失败回调
- * @param errorMessage
- */
- @Override
- public void onLoadError(String errorMessage) {
- super.onLoadError(errorMessage);
- }
-
- /**
- * 加载VR图片成功回调
- */
- @Override
- public void onLoadSuccess() {
- super.onLoadSuccess();
- }
-
- /**
- * 点击VR图片回调
- */
- @Override
- public void onClick() {
- super.onClick();
- }
- });
- /**加载VR图片**/
- binding.supermarketVr.loadImageFromBitmap(bitmap, options);
- }
- }
效果图:
综合转载两篇文章:Android移动开发-VR全景照片简单实现 - 全栈程序员必看
【Android开发VR实战】一.给用户呈现一个360°全景图片_DylanAndroid的博客-CSDN博客_android vr开发
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。