VR image

来源:互联网 发布:淘宝买家已付款生成器 编辑:程序博客网 时间:2024/06/04 19:40

引入:
compile ‘com.google.vr:sdk-panowidget:1.10.0’

<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="test.bwie.com.vrimages.MainActivity">    <com.google.vr.sdk.widgets.pano.VrPanoramaView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/vrpan"        /></RelativeLayout>

Main:
package test.bwie.com.vrimages;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.google.common.logging.nano.Vr;
import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener;
import com.google.vr.sdk.widgets.pano.VrPanoramaView;

import java.io.IOException;
import java.io.InputStream;

public class MainActivity extends AppCompatActivity {

private VrPanoramaView  vr;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    load360Image();}private void load360Image() {    vr = (VrPanoramaView) findViewById(R.id.vrpan);    /**获取assets文件夹下的图片**/    InputStream opens = null;    try {      opens = getAssets().open("re.jpg");    } catch (Exception e) {        e.printStackTrace();    }    Bitmap bitmap  = BitmapFactory.decodeStream(opens);    /**设置加载VR图片的相关设置**/    VrPanoramaView.Options options = new VrPanoramaView.Options();    options.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER;    //监听    vr.setEventListener(new VrPanoramaEventListener(){        /**         * 显示模式改变回调         * 1.默认         * 2.全屏模式         * 3.VR观看模式,即横屏分屏模式         * @param newDisplayMode 模式         */        @Override        public void onDisplayModeChanged(int newDisplayMode) {            super.onDisplayModeChanged(newDisplayMode);        }        //加载失败        @Override        public void onLoadError(String errorMessage) {            super.onLoadError(errorMessage);            Toast.makeText(MainActivity.this, "失败了 好蠢啊", Toast.LENGTH_SHORT).show();        }        //加载成功        @Override        public void onLoadSuccess() {            super.onLoadSuccess();            Toast.makeText(MainActivity.this, "加载成功了哦", Toast.LENGTH_SHORT).show();        }        //点击vr图片回调        @Override        public void onClick() {            super.onClick();            Toast.makeText(MainActivity.this, "你点击了我 好疼", Toast.LENGTH_SHORT).show();        }    });    vr.loadImageFromBitmap(bitmap,options);}

}

原创粉丝点击