Android 谷歌推薦的VR實(shí)現(xiàn)方式(分享)
谷歌有專門的SDK來(lái)完成VR,我這次以一個(gè)全景圖片的例子來(lái)說(shuō)一下這個(gè)SDK實(shí)現(xiàn)VR的基本過(guò)程,首先全景圖片就是百度地圖里的那樣,能夠看到周圍環(huán)境360的圖片。
添加依賴
compile 'com.google.vr:sdk-panowidget:1.80.0'
添加權(quán)限
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.GET_TASKS"/>
實(shí)現(xiàn)代碼
public class GoogleVRActivity extends AppCompatActivity {
private VrPanoramaView mVrPanoramaView;
private VrPanoramaView.Options paNormalOptions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_vr);
initVrPaNormalView();
}
@Override
protected void onPause() {
super.onPause();
mVrPanoramaView.pauseRendering();
}
@Override
protected void onResume() {
super.onResume();
mVrPanoramaView.resumeRendering();
}
@Override
protected void onDestroy() {
// Destroy the widget and free memory.
super.onDestroy();
mVrPanoramaView.shutdown();
}
//初始化VR圖片
private void initVrPaNormalView() {
mVrPanoramaView = (VrPanoramaView) findViewById(R.id.mVrPanoramaView);
paNormalOptions = new VrPanoramaView.Options();
paNormalOptions.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER;
// mVrPanoramaView.setFullscreenButtonEnabled (false); //隱藏全屏模式按鈕
mVrPanoramaView.setInfoButtonEnabled(false); //設(shè)置隱藏最左邊信息的按鈕
mVrPanoramaView.setStereoModeButtonEnabled(false); //設(shè)置隱藏立體模型的按鈕
mVrPanoramaView.setEventListener(new ActivityEventListener()); //設(shè)置監(jiān)聽(tīng)
//加載本地的圖片源
mVrPanoramaView.loadImageFromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.andes), paNormalOptions);
//設(shè)置網(wǎng)絡(luò)圖片源
// panoWidgetView.loadImageFromByteArray();
}
private class ActivityEventListener extends VrPanoramaEventListener {
@Override
public void onLoadSuccess() {//圖片加載成功
}
@Override
public void onLoadError(String errorMessage) {//圖片加載失敗
}
@Override
public void onClick() {//當(dāng)我們點(diǎn)擊了VrPanoramaView 時(shí)候觸發(fā) super.onClick();
}
@Override
public void onDisplayModeChanged(int newDisplayMode) {
//改變顯示模式時(shí)候出發(fā)(全屏模式和紙板模式)
super.onDisplayModeChanged(newDisplayMode);
}
}
}
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dip" android:id="@+id/main_layout" android:orientation="vertical" > <TextView style="@style/ContentText" android:id="@+id/title" android:textSize="@dimen/title_text_size" android:textStyle="bold" android:textColor="@color/colorAccent" android:text="第二種谷歌官方VR演示" /> <TextView style="@style/ContentText" android:id="@+id/subtitle" android:textColor="@color/colorAccent" android:textSize="@dimen/caption_text_size" android:text="谷歌紙殼子demo" /> <TextView style="@style/ContentText" android:id="@+id/paragraph1" android:textColor="@color/colorAccent" android:textSize="@dimen/paragragh_text_size" android:text="魚和熊掌不可兼得" /> <com.google.vr.sdk.widgets.pano.VrPanoramaView android:id="@+id/mVrPanoramaView" android:layout_width="match_parent" android:layout_height="250dip"/> </LinearLayout> </ScrollView>
VrPanoramaView這個(gè)類和Activity有著類似的生命周期,全屏顯示是它自己設(shè)置的,這個(gè)VR 的SDK完成度很高,可以多去參考。
以上這篇Android 谷歌推薦的VR實(shí)現(xiàn)方式(分享)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android為TextView添加字體庫(kù)和設(shè)置描邊的方法
本篇文章主要介紹了Android為TextView添加字體庫(kù)和設(shè)置描邊的方法,具有一定的參考價(jià)值,有興趣的可以了解一下2017-09-09
Android編程之SurfaceView實(shí)例詳解
這篇文章主要介紹了Android編程之SurfaceView用法,簡(jiǎn)要分析了View和SurfaceView的區(qū)別,并結(jié)合實(shí)例形式分析了SurfaceView的具體使用步驟與相關(guān)技巧,需要的朋友可以參考下2016-02-02
Android 使用SharePerference判斷是否為第一次登陸的實(shí)現(xiàn)代碼
很多app中在第一次安裝登陸時(shí)會(huì)有引導(dǎo)歡迎界面,第二次打開(kāi)時(shí)就不再顯示引導(dǎo)頁(yè)面。這個(gè)怎么實(shí)現(xiàn)呢?下面小編給大家介紹下使用SharePerference判斷是否為第一次登陸的實(shí)現(xiàn)代碼,需要的的朋友參考下吧2017-03-03
Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
Android開(kāi)發(fā)之EditText框輸入清理工具類示例
這篇文章主要介紹了Android開(kāi)發(fā)之EditText框輸入清理工具類,涉及Android事件監(jiān)聽(tīng)及輸入框清理相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
android 獲取手機(jī)GSM/CDMA信號(hào)信息,并獲得基站信息的方法
下面小編就為大家?guī)?lái)一篇android 獲取手機(jī)GSM/CDMA信號(hào)信息,并獲得基站信息的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11
Android編程實(shí)現(xiàn)Listview點(diǎn)擊展開(kāi)和隱藏的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)Listview點(diǎn)擊展開(kāi)和隱藏的方法,涉及Android中Listview的響應(yīng)點(diǎn)擊與樣式變換相關(guān)操作技巧,需要的朋友可以參考下2015-12-12
android計(jì)時(shí)器,時(shí)間計(jì)算器的實(shí)現(xiàn)方法
android計(jì)時(shí)器,時(shí)間計(jì)算器的實(shí)現(xiàn)方法,需要的朋友可以參考一下2013-03-03
Android 實(shí)現(xiàn)切圓圖作為頭像使用實(shí)例
這篇文章主要介紹了Android 實(shí)現(xiàn)切圓圖作為頭像使用實(shí)例的相關(guān)資料,需要的朋友可以參考下2016-12-12

